Category / Section
How to draw the header and footer outside the bounds of the margin?
1 min read
You can draw the header and footer outside of the margin by using the following steps:
- Create a PDF with Margin(Margins.All=value).
- Save the document to the MemoryStream and load it via the PdfLoadedDocument.
- Convert the loaded document pages to templates.
- Create a new PdfDocument with margins set to zero.
- Draw the loaded pages template onto the new templates.
- Add the header and footer to the new document template.
Refer to the following code example to draw the header outside the margin.
C#
//Load the file stream that contains the PdfLoadedDocument ldoc = new PdfLoadedDocument(ms); //Create the document. PdfDocument finalDoc = new PdfDocument(); //Get the templates from loadeddocument. PdfTemplate template = ldoc.Pages[i].CreateTemplate(); finalDoc.Pages.Add(); finalDoc.Pages[i].Graphics.DrawPdfTemplate(template, new PointF(0, 0)); //Add the header outside the bounds of the margin. PdfPageTemplateElement header = new PdfPageTemplateElement(50, 0,100, 50); finalDoc.Template.Top = header;
Sample Link:
https://www.syncfusion.com/downloads/support/directtrac/general/MarginSample-279672044.zip