2
votes

In the Migradoc and PDFSharp samples page, there is one that draws a Migradoc Document into a PDFSharp Document: http://www.pdfsharp.net/wiki/MixMigraDocAndPdfSharp-sample.ashx

But what about if the Migradoc document I want to render has more than one page? In Migradoc you don't handle pages.. it is done automatically.

EDIT: FOUND MY WAY

Well, once you "Prepare()" the document... you have the FormattedDocument() method, and there you can see how many pages it ends up having. I added my own response to this below.

1

1 Answers

4
votes

Once you Prepare() the Migradoc document, you have the layout of your document, and the number of pages. So, you just need to loop over each page of the MigraDoc document, and for each one you need to create a page in the PdfDocument:

private void SampleMultiplePage(ref PdfDocument document, Document migraDocument)
        {
            var pdfRenderer = new DocumentRenderer(migraDocument);

            pdfRenderer.PrepareDocument();

            int pages = pdfRenderer.FormattedDocument.PageCount;
            for (int i = 1; i <= pages; ++i)
            {
                var page = document.AddPage();

                PageInfo pageInfo = pdfRenderer.FormattedDocument.GetPageInfo(i);
                page.Width = pageInfo.Width;
                page.Height = pageInfo.Height;
                page.Orientation = pageInfo.Orientation;

                using (XGraphics gfx = XGraphics.FromPdfPage(page))
                {
                    // HACKĀ²
                    gfx.MUH = PdfFontEncoding.Unicode;
                    gfx.MFEH = PdfFontEmbedding.Default;

                    pdfRenderer.RenderPage(gfx, i);
                }
            }
        }