Word Documents in Headers and Footers | |
PdfWordSection puts a Word document into the header or footer band of a converted document, the way PdfHtmlSection puts html there. The document is given as a file path or a stream, in any format the Word converter reads. It is rendered once, with every page set to the size of the band and no margins of its own - the band is the paper - and the first rendered page is drawn on every page that shows the band, scaled to the band's width and cut at its height, never stretched. Its web links stay clickable on every page.
A section is independent of the converter it heads: a Word band can head the pages of a WordToPdf conversion or of an HtmlToPdf one, and an html band can head a Word conversion.
PdfWordSection is available only in the full commercial SelectPdf library. |
A Word file as the header of a Word conversion, and a page-number footer. PageRanges chooses which rendered page the band shows when the header document has several.
WordToPdf converter = new WordToPdf(); converter.Options.DisplayHeader = true; converter.Header.Height = 50; converter.Header.Add(new PdfWordSection("header.docx")); converter.Options.DisplayFooter = true; converter.Footer.Height = 30; converter.Footer.Add(new PdfTextSection(0, 10, 500, "Page {page_number} of {total_pages}", PdfFont.CreateStandardFont(PdfStandardFont.Helvetica, 9), new PdfColor(80, 80, 80))); PdfDocument doc = converter.ConvertFile("report.docx"); doc.Save("report.pdf"); doc.Close();
The same band heading an html conversion:
The document's own page margins are not kept: a file made in Word carries one-inch margins, and a 50-point band cannot hold two of them - the text would land entirely outside the band. Place the content inside the band with X, Y, Width and Height instead.