Thanks for the link, had a looked at your samples, I was unable to find how to import a pdf document into a Migradoc document directly.
I figured this method using the examples but there has to be an easier way, please advise.
step 1 Create a blank pdf sharp document
step 2 add the dynamically generated migradoc in to the blank pdf
step 3 import the normal pdf simply via PdfReader
Code:
static double A4Width = XUnit.FromCentimeter(21).Point;
static double A4Height = XUnit.FromCentimeter(29.7).Point;
public PDFDocumentImportTest()
{
string filename = "MixMigraDocAndPdfSharp.pdf";
filename = Guid.NewGuid().ToString("D").ToUpper() + ".pdf";
PdfDocument mainPDF = new PdfDocument();
MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(PdfDocumentObj);
docRenderer.PrepareDocument();
XRect A4Rect = new XRect(0, 0, A4Width, A4Height);
int pageCount = docRenderer.FormattedDocument.PageCount;
for (int idx = 0; idx < pageCount; idx++)
{
PdfPage mainPdfPage = mainPDF.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(mainPdfPage);
// HACKĀ²
gfx.MUH = PdfFontEncoding.Unicode;
gfx.MFEH = PdfFontEmbedding.Default;
// Use BeginContainer / EndContainer for simplicity only. You can naturaly use you own transformations.
XGraphicsContainer container = gfx.BeginContainer(A4Rect, A4Rect, XGraphicsUnit.Point);
// Render the page. Note that page numbers start with 1.
docRenderer.RenderPage(gfx, idx + 1);
// Note: The outline and the hyperlinks (table of content) does not work in the produced PDF document.
// Pop the previous graphical state
gfx.EndContainer(container);
}
PdfDocument pdfInFile = PdfReader.Open(@"C:\Temp\Already_Generated_PDF_Report.pdf", PdfDocumentOpenMode.Import);
foreach (PdfPage p in pdfInFile.Pages)
{
mainPDF.AddPage(p);
}
mainPDF.Save(filename);
Process.Start(filename);
}
Is the above correct? is there an easier method? How would you reorder the page numbers?(a hint)
Thanks