EVO HTML to PDF Converter offers a great flexibility in adding headers and footers to the generated PDF document. You can add in header and footer any PDF element that you can normally add in a PDF page : HTML, text, image.
The most important options related to adding HTML in header and footer:
Enable Header and Footer
Add Header. Using this option you can enable or disable the header in the generated PDF document. The method you call to add a header to a PDF document is DocumentAddHeaderTemplate(Single)
Add Footer. Using this option you can enable or disable the footer in the generated PDF document. The method you call to add a footer to a PDF document is DocumentAddFooterTemplate(Single)
Header Options
Show in First Page. You can enable or disable the header in the first page of the generated PDF document using the property PdfPageShowHeader of the first page of the document.
Show in Odd Pages. You can enable or disable the header in the odd pages of the generated PDF document using the HtmlToPdfElementShowHeaderInOddPages property.
Show in Even Pages. You can enable or disable the header in the even pages of the generated PDF document using the HtmlToPdfElementShowHeaderInEvenPages property.
Draw Header Line. This feature controls if a thin line will be drawn at the bottom of the header and it can be implemented by adding a EvoPdf.HtmlToPdfClientLineElement object at the bottom of the header template.
Spacing. This option represents the space between the header and the PDF page body. The property you can set in your code for this option is HtmlToPdfElementTopSpacing.
First Page Spacing. This option represents the space between the header and the PDF page body in the first page of the generated PDF document. The property you can set in your code for this option is HtmlToPdfElementY.
Footer Options
Show in First Page. You can enable or disable the footer in the first page of the generated PDF document using the property PdfPageShowFooter of the first page of the document.
Show in Odd Pages. You can enable or disable the footer in the odd pages of the generated PDF document using the HtmlToPdfElementShowFooterInOddPages property.
Show in Even Pages. You can enable or disable the footer in the even pages of the generated PDF document using the HtmlToPdfElementShowFooterInEvenPages property.
Add Page Numbers. This feature controls if the page numbering will be added in footer and it can be implemented by using the &p; and &P; place holders for current page number and the total numer of page of the PDF document in a EvoPdf.HtmlToPdfClientTextElement added to the footer template
Draw Footer Line. This feature controls if a thin line will be drawn at the top of the footer and it can be implemented by adding a EvoPdf.HtmlToPdfClientLineElement object at the top of the footer template.
Spacing. This option represents the space between the footer and the PDF page body. The property you can set in your code for this option is HtmlToPdfElementBottomSpacing.
protected void createPdf() { // Get the server IP and port String serverIP = textBoxServerIP.Text; uint serverPort = uint.Parse(textBoxServerPort.Text); // Create a PDF document Document pdfDocument = null; if (radioButtonUseTcpService.Checked) pdfDocument = new Document(serverIP, serverPort); else pdfDocument = new Document(true, textBoxWebServiceUrl.Text); // Set optional service password if (textBoxServicePassword.Text.Length > 0) pdfDocument.ServicePassword = textBoxServicePassword.Text; // Set license key received after purchase to use the converter in licensed mode // Leave it not set to use the converter in demo mode pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c="; // Add a PDF page to PDF document PdfPage pdfPage = pdfDocument.AddPage(); HtmlToPdfElement htmlToPdfElement = null; // Add document header if (addHeaderCheckBox.Checked) AddHeader(pdfDocument, drawHeaderLineCheckBox.Checked); // Add document footer if (addFooterCheckBox.Checked) AddFooter(pdfDocument, addPageNumbersInFooterCheckBox.Checked, drawFooterLineCheckBox.Checked); // Create a HTML to PDF element to add to document htmlToPdfElement = new HtmlToPdfElement(0, 0, urlTextBox.Text); // Optionally set a delay before conversion to allow asynchonous scripts to finish htmlToPdfElement.ConversionDelay = 2; // Optionally add a space between header and the page body // Leave this option not set for no spacing htmlToPdfElement.Y = float.Parse(firstPageSpacingTextBox.Text); htmlToPdfElement.TopSpacing = float.Parse(headerSpacingTextBox.Text); // Optionally add a space between footer and the page body // Leave this option not set for no spacing htmlToPdfElement.BottomSpacing = float.Parse(footerSpacingTextBox.Text); // Set header visibility pdfDocument.GetPage(0).ShowHeader = showHeaderInFirstPageCheckBox.Checked; htmlToPdfElement.ShowHeaderInEvenPages = showHeaderInEvenPagesCheckBox.Checked; htmlToPdfElement.ShowHeaderInOddPages = showHeaderInOddPagesCheckBox.Checked; // Set footer visibility pdfDocument.GetPage(0).ShowFooter = showFooterInFirstPageCheckBox.Checked; htmlToPdfElement.ShowFooterInEvenPages = showFooterInEvenPagesCheckBox.Checked; htmlToPdfElement.ShowFooterInOddPages = showFooterInOddPagesCheckBox.Checked; // Add the HTML to PDF element to document // This will raise the PrepareRenderPdfPageEvent event where the header and footer visibilit per page can be changed pdfPage.AddElement(htmlToPdfElement); // Save the PDF document in a memory buffer byte[] outPdfBuffer = pdfDocument.Save(); }