【问题标题】:Automatic New Page based on text基于文本的自动新页面
【发布时间】:2011-03-16 11:10:07
【问题描述】:

你好 我已经成功地使用了这个很棒的库 PDF Sharp。现在我想玩一些动态的东西,所以人们建议我切换到 Migradoc,我喜欢它的段落功能。现在的问题是,当我添加长段落时,新页面不是添加而不是显示不完整的文本(不完整的意思是文本溢出)并且我在底部添加了一个图像以供页脚查看。我该怎么做才能输入动态文本(可变长度),它只是添加所需的数字页数。

到目前为止我的代码是

 XFont font = new XFont("Times New Roman", 12, XFontStyle.Bold);
            XFont fontReg = new XFont("Times New Roman", 12, XFontStyle.Regular);

            // HACK²
            gfx.MUH = PdfFontEncoding.Unicode;
            gfx.MFEH = PdfFontEmbedding.Default;

            string appPath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
            XImage image = XImage.FromFile(appPath + "/header.png");
            gfx.DrawImage(image, 0, 0);
            //Civil Stamp
            gfx.DrawImage(XImage.FromFile(appPath + "/cStamp.png"), 370, 380);

            gfx.DrawImage(XImage.FromFile(appPath + "/Sp.png"), 230, 380);

            CoverPageHeader();

            Document doc = new Document();
            MigraDoc.DocumentObjectModel.Section sec = doc.AddSection();
            // Add a single paragraph with some text and format information.
            MigraDoc.DocumentObjectModel.Paragraph para = sec.AddParagraph();
            para.Format.Alignment = ParagraphAlignment.Left;
            para.Format.Font.Name = "Times New Roman";
            para.Format.Font.Size = 12;
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black;

            para.AddText("We are pleased to present the attached Document Please review the Agreement and, if acceptable, " +
                "sign one copy and return it to us.  We will sign the copy of the agreement and return one for " +
                "your records.");

            para.AddLineBreak();
            para.AddLineBreak();
            para.AddText(longlongtextString);
            para.AddLineBreak();
            para.AddLineBreak();            
            para.AddText("Sincerely,");

 MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(0.7), XUnit.FromCentimeter(9), "18cm", para);

            gfx.DrawString("Kelly Turbin PhD., P.E.-SECB", font, XBrushes.Black, 20, 500);
            gfx.DrawString("Principal", font, XBrushes.Black, 20, 520);
            gfx.DrawString("Project No " + textBoxProjNumber.Text, fontReg, XBrushes.Black, 20,785);

            gfx.DrawImage(XImage.FromFile(appPath + "/AccB.png"), 20, 700);
            gfx.DrawImage(XImage.FromFile(appPath + "/ScreenMagic.png"), 100, 690);
            gfx.DrawImage(XImage.FromFile(appPath + "/Footer.png"), 220, 750);

        }

【问题讨论】:

    标签: c# wpf pdfsharp migradoc


    【解决方案1】:

    不要使用 RenderObject,而是使用 RenderDocument,页面会根据需要自动创建。

    此处的示例代码: http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

    【讨论】:

    • docRenderer.RenderDocument 没有选项,只有 RenderObject 和 RenderPage 两种方法可用
    • 如果我更改代码的最后几行,则 pdf PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);渲染器.文档 = 文档; renderer.RenderDocument();
    【解决方案2】:

    当您使用Mix of PDFSharp and MigraDoc 时,无法根据文本大小自动创建新页面,因为它在问题中。唯一的解决方案是仅使用 MigraDoc 及其 RenderDocument 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-06
      • 2010-10-19
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多