I am using ABCPDF and using the MSHTML engine for a certain report. It loads .PNG files fine, and our extensionless handler images, but when it comes to .jpg it shows an X. The pure HTML loads fine, but converting the html to PDF it doesnt load.
The other images in the screenshot are either PNG or extensionless. Also the Chrome Engine loads the image.
I even did a test with the same exact image, just different in how its sent to the browser. The first one is the image handler, that returns a JPG, and the second is reading the file directly from the file system. The handler works, but the one with the extension doesnt.
Any clue on why this is happening with the MSHTML engine?
/assets/files/210057 <-- Loads
/assets/files/210057.jpg <-- DOESNT
string theDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName @"\files\";
string theURL = "file://" theDir "source.html";
using (Doc doc = new Doc())
{
doc.MediaBox.String = "Letter";
// Convert HTML
doc.Pos.Y = 0;
doc.Rect.Inset(0, 0);
doc.HtmlOptions.Engine = EngineType.MSHtml;
doc.Rect.String = doc.MediaBox.String;
var w = doc.MediaBox.Width;
var h = doc.MediaBox.Height;
var l = doc.MediaBox.Left;
var b = doc.MediaBox.Bottom;
doc.Transform.Rotate(90, l, b);
doc.Transform.Translate(w, 0);
doc.Rect.Width = h;
doc.Rect.Height = w;
int theID = doc.AddImageUrl(theURL, true, 800, true);
doc.SetInfo(doc.GetInfoInt(doc.Root, "Pages"), "/Rotate", "90");
while (true)
{
if (!doc.Chainable(theID)) break;
doc.Page = doc.AddPage();
theID = doc.AddImageToChain(theID);
}
for (int i = 1; i <= doc.PageCount; i )
{
doc.PageNumber = i;
doc.Flatten();
}
string outFile = Path.Combine(theDir, $"out{XSettings.Version}{doc.HtmlOptions.Engine}.pdf");
doc.Save(outFile);
doc.Clear();
}
CodePudding user response:
Well it turned out to be this added customHeader in the Web.Config. I will now either switch to ABCChrome or try to ignore this on images with a url rewrite rule.
<add name="X-Content-Type-Options" value="nosniff" />