The PDF document Header and Footer classes are a specialization of the PDF Repeat Canvas represented by the PdfDocumentHeader and PdfDocumentFooter. classes. The document header and footer can be created using the PdfDocumentCreateHeaderCanvas(Single) and PdfDocumentCreateFooterCanvas(Single) methods
Below is an example of creating a repeat canvas taken from the In Place HTML to PDF Object demo application:
Create Repeat Canvas Sample Source Code
C#
private void SetHeader(PdfDocument document) { if (!checkBoxAddHeader.Checked) return; // create the document header document.CreateHeaderCanvas(50); // add PDF objects to the header canvas string headerImageFile = Application.StartupPath + @"\DemoFiles\Images\HiQPdfLogo.png"; PdfImage logoHeaderImage = new PdfImage(5, 5, 40, Image.FromFile(headerImageFile)); document.Header.Layout(logoHeaderImage); // layout HTML in header PdfHtml headerHtml = new PdfHtml(50, 5, @"<span style=""color:Navy; font-family:Times New Roman; font-style:italic""> Quickly Create High Quality PDFs with </span><a href=""http://www.hiqpdf.com"">HiQPdf</a>", null); headerHtml.FitDestHeight = true; headerHtml.FontEmbedding = true; document.Header.Layout(headerHtml); // create a border for header float headerWidth = document.Header.Width; float headerHeight = document.Header.Height; PdfRectangle borderRectangle = new PdfRectangle(1, 1, headerWidth - 2, headerHeight - 2); borderRectangle.LineStyle.LineWidth = 0.5f; borderRectangle.ForeColor = Color.Navy; document.Header.Layout(borderRectangle); } private void SetFooter(PdfDocument document) { if (!checkBoxAddFooter.Checked) return; //create the document footer document.CreateFooterCanvas(50); // layout HTML in footer PdfHtml footerHtml = new PdfHtml(5, 5, @"<span style=""color:Navy; font-family:Times New Roman; font-style:italic""> Quickly Create High Quality PDFs with </span><a href=""http://www.hiqpdf.com"">HiQPdf</a>", null); footerHtml.FitDestHeight = true; footerHtml.FontEmbedding = true; document.Footer.Layout(footerHtml); float footerHeight = document.Footer.Height; float footerWidth = document.Footer.Width; // add page numbering Font pageNumberingFont = new Font(new FontFamily("Times New Roman"), 8, GraphicsUnit.Point); //pageNumberingFont.Mea PdfText pageNumberingText = new PdfText(5, footerHeight - 12, "Page {CrtPage} of {PageCount}", pageNumberingFont); pageNumberingText.HorizontalAlign = PdfTextHAlign.Center; pageNumberingText.EmbedSystemFont = true; pageNumberingText.ForeColor = Color.DarkGreen; document.Footer.Layout(pageNumberingText); string footerImageFile = Application.StartupPath + @"\DemoFiles\Images\HiQPdfLogo.png"; PdfImage logoFooterImage = new PdfImage(footerWidth - 40 - 5, 5, 40, Image.FromFile(footerImageFile)); document.Footer.Layout(logoFooterImage); // create a border for footer PdfRectangle borderRectangle = new PdfRectangle(1, 1, footerWidth - 2, footerHeight - 2); borderRectangle.LineStyle.LineWidth = 0.5f; borderRectangle.ForeColor = Color.DarkGreen; document.Footer.Layout(borderRectangle); }
See Also