Thank you @TH-Soft
Yes, I didn't realize how simple it actually was. I assumed MigraDoc didn't have such rich support for headers. Here is what I ended up doing:
Code:
Document migraDocDocument = new Document();
migraDocDocument.Styles["Normal"].Font.Name = "Courier New";
var section = migraDocDocument.AddSection();
section.Headers.FirstPage.AddParagraph("First page header");
section.PageSetup.DifferentFirstPageHeaderFooter = true;
section.Headers.Primary.AddParagraph("This is my header");
section.PageSetup.PageFormat = PageFormat.Letter;
section.AddParagraph(
"Lorem ipsum dolor sit amet"
);
PdfDocumentRenderer pdfDocumentRenderer = new PdfDocumentRenderer();
pdfDocumentRenderer.Document = migraDocDocument;
pdfDocumentRenderer.RenderDocument();
using (MemoryStream memoryStream = new MemoryStream())
{
pdfDocumentRenderer.PdfDocument.Save(memoryStream, false);
// Open the PDF document from the memory stream with the desired PdfDocumentOpenMode
using (var streamedPdfDocument = PdfReader.Open(memoryStream, PdfDocumentOpenMode.Import))
{
foreach (var current in streamedPdfDocument.Pages)
{
document.AddPage(current);
}
}
}
One question though, it looks like you can't embed a PDF in the Header without first rendering it as an image, is that correct?