We’ve spent many many frustrating hours this week trying to make sense of what happens when inserting a HTML fragment into a PDF’s document header / footer.
Example simplified code:
Aspose.Pdf.HeaderFooter pdfHeaderFooter = new Aspose.Pdf.HeaderFooter();
doc.Pages[i].Header = pdfHeaderFooter;
doc.Pages[i].Footer = pdfHeaderFooter;
What we have observed:
- If the parent div contains a width entry in an inline style (pretty common thing to do!) then the page borders set on the PDF document then control the starting point as to where the HTML fragment is inserted… if you remove the width style then it will ingore the page borders.
- As above, the same behaviour has been observed when the HTML references an external image.
A bit annoying but there is an easy fix! simple, just set the left, right and top page margin properties to 0 and then add the fragment!, example:
doc.Pages[i].PageInfo.Margin.Left = 0d;
Now, this does allow the HTML fragment to contain pretty much any HTML… however, any page where the header / footer has been inserted results in a slightly wider page than the original page. (see attached image)
extraPageWidth.jpg (8.3 KB)
Neither of these scenarios is particularly good… cab you advise please?