首页 文章

将多页MigraDoc文档添加到PDFSharp文档

提问于
浏览
2

在Migradoc和PDFSharp示例页面中,有一个将Migradoc文档绘制到PDFSharp文档中:http://www.pdfsharp.net/wiki/MixMigraDocAndPdfSharp-sample.ashx

But what about if the Migradoc document I want to render has more than one page? 在Migradoc中,您不处理页面..它是自动完成的 .

EDIT: FOUND MY WAY

好吧,一旦你“准备()”文档...你有FormattedDocument()方法,在那里你可以看到它最终有多少页面 . 我在下面添加了自己的回复 .

1 回答

  • 3

    一旦您使用了Migradoc文档,就可以获得文档的布局和页数 . 因此,您只需要遍历MigraDoc文档的每个页面,并且对于每个页面,您需要在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);
                    }
                }
            }
    

相关问题