Search code examples
pdfsharpmigradoc

MigraDoc PDFSharp Add Page Borders


How do I add Borders to every page of PDF Doc (variable page numbers) using MigraDoc?


Solution

  • Drawing a simple rectangle around the whole page should work using e.g. a TextFrame that is added to the page header. TextFrame can have an absolute position, can have any size, and can have a border (width and color can be set).

    You can mix MigraDoc and PDFsharp and use PDFsharp functions to draw the borders. See also: http://www.pdfsharp.net/wiki/MixMigraDocAndPdfSharp-sample.ashx

    Here's a sample that calls RenderPage to draw each page: http://forum.pdfsharp.net/viewtopic.php?p=1735#p1735 You can use the gfx object to draw the borders (before or after RenderPage).

    You can also draw a predefined PDF page using the XImage class before calling RenderPage. This allows you to prepare sophisticated borders using e.g. InDesign and mix that with your MigraDoc document. That's overkill if you simply want a black frame, but it's very simple if the corporate design is already available as a PDF file.