Hi,
We provide several methods for you to add header and footer. You can choose either one or a combination of multiple methods depending on your personal preference or which way is more convenient for you.
The basic idea of adding header and footer is the same as outputting anything else ---- except that you are outputting to a page that already has contents on it. For example, the following sample convert Google’s home page and then add a header on it:
Code: C#
//Output the main content
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertUrl("http://www.google.com", doc);
//Output header. Points of interest:
//1. You must set OutputArea to override the default output
// area. The default output area has a 1 inch margin on
// all sides;
//2. The second argument of ConvertHtml is a PdfPage object.
// This explicitly outputs to the specified page;
HtmlToPdf.Options.OutputArea = new Rectangle(0, 0, 8, 11);
HtmlToPdf.ConvertHtml("header text", doc.Pages[0]);
As such, the most straight forward way for you to create header/footer is to create all the PDF files first, then run a loop on all PdfPage object to add the footer and header.
There are several alternatives but they all based on the same idea:
1. Instead of using ConvertHtml to output header/footer, you can use ACM (The PDF Creator interface). ACM is more "object oriented" comparing with HTML which is markup based;
2. Instead of rendering header/footer afterwards in a loop, you can handle BeforeRenderPage/AfterRenderPage to render your header/footer. There is no signficant difference between these two events and rendering it in a loop. It's just a matter of different coding structures/styles;
3. If you only use HTML to PDF and only has simple header/footer, then you can set HtmlToPdf.Options.HeaderHtmlFormat and FooterHtmlFormat and have the converter to automatically add header/footer for you;
Hope this helps. Please feel free to let us know if you have any more questions.
Thanks!