Pdfsharp和MigradDoc:如何使用migradoc和pdfsharp使正确的白色面板响应?

时间:2017-02-13 06:19:06

标签: .net pdfsharp migradoc

//-- migradoc----------
    <code>
          Document document = new Document();
          Section section = document.AddSection();
          Paragraph paragraph = section.AddParagraph();
    </code>

// --- pdfSharp ---------------------------

    <code>
        PdfDocument layoutDoc = new PdfDocument();
        PdfPage page = layoutDoc.AddPage();
        XGraphics gfx = CreatePageLayout(page);
        XFont font = new XFont("Verdana", 12);
    </code>

// ---渲染migradoc对象--------------------------------------- ------ // ---这里的文档是migradoc文档,其中包含将在pdfsharp文档中使用的所有数据          MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(document); docRenderer.PrepareDocument(); //---Length Tags int leftPanelYaxis = 0; int RightPanelHeight = 0; try { // Render the paragraph.You can render tables or shapes the same way. docRenderer.RenderObject(gfx, XUnit.FromCentimeter(0.7), XUnit.FromCentimeter(0.5), "6cm", name); docRenderer.RenderObject(gfx, XUnit.FromCentimeter(0.7), XUnit.FromCentimeter(2), "6cm", about); docRenderer.RenderObject(gfx, XUnit.FromCentimeter(0.3), XUnit.FromCentimeter(2), "0.6cm", aboutme_icon); }

    [Below is the image of the Resume. The Left side is fixed and the right needs to be responsive. Currently I will have to handle the content and give coordinates to add it on pdfSharp document. In migradoc this is handled but the left colored panel has fixed data. This cannot be achieved in migraDoc alone. So there has to be some combination of migraDoc and PdfSharp.][1]][1 // ---如何使这个右侧动态。 migradoc已经有了这个功能来实现这一目标。但左侧面板是彩色和固定的,而右侧面板将响应。如何实现这一目标。 目前,右侧面板上的数据是溢出和重叠的,因为它是一个页面。当我渲染Migradoc的对象时,它在pdfsharp文档中溢出。有没有办法解决这个问题。

2 个答案:

答案 0 :(得分:0)

RenderObject无法处理分页符。您只能将它用于将单个对象渲染到单个页面。您可以使用自定义页面大小使页面变得非常大。

RenderPage负责分页。创建包含多个对象的文档,然后使用RenderPage绘制它 可以在此处看到使用RenderPage(用于不同目的)的示例:
http://forum.pdfsharp.net/viewtopic.php?f=8&t=3172

如果您需要,可以从FormattedDocument查询有关对象大小和位置的信息。

答案 1 :(得分:0)

     /// <summary>
            /// Merge Left and Right Panels
            /// </summary>
            /// <param name="rightPanelMigraDoc"></param>
            /// <param name="leftPanelPdfDoc"></param>
            /// <param name="gfx"></param>
    <code>
            public static void MergePanels(Document migraDocument, PdfDocument leftPanelPdfDoc, XGraphics gfx)
            {
                PdfPage page = null;

                //concatenation of Left and Right Panels 
                // Create a renderer and prepare (layout) the Migradoc document
                MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(migraDocument);
                docRenderer.PrepareDocument();

                //get pagecount of the rightpanelMigraDoc
                int rightPageCount = docRenderer.FormattedDocument.PageCount;
                int leftPageCount = leftPanelPdfDoc.PageCount;
                // Loop to add leftPanel pages equal to rightPanel and Merge by rendering
                int index = 0;
                do
                {
                    //for single left panel page only.
                    if (index == 0)
                    {
                        docRenderer.RenderPage(gfx, index + 1);
                        index++;
                    }
                    else
                    {
                        page = leftPanelPdfDoc.AddPage();
                        page.Size = PdfSharp.PageSize.A4;
                        gfx = CreatePageLayout(page);
                        // Render the page. Note that page numbers start with 1.
                        docRenderer.RenderPage(gfx, index + 1);
                        index++;
                    }
                }
                while (index < rightPageCount);
            }
    </code>

但是这一个适用于单个左页和响应右侧面板(页面添加到pdfsharp文档中,然后使用该gfx在其上呈现MigraDoc页面)。 然而,这可以改进,使左侧面板也首先有多个页面,然后获取每个页面的gfx(XGraphics对象)并呈现右侧面板MigraDoc