基于文本的自动新页面

发布于 2024-10-22 02:52:31 字数 2770 浏览 7 评论 0原文

你好呀 我已经成功地使用了这个很棒的 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);

        }

Hi there
i had been sucessfully using this great library PDF Sharp.now i wanted to play with some dynamic Stuff so people recomended to switch to Migradoc I did and like its paragraph feature.Now the problem is that when i add long paragraph then new page is not added instead of that there is incomplete text shown(incomplete in sense that text overflows) and i have added a image at the bottom for footer look.how can i do that i enter dynamic text (variable length ) and it just adds the required Number of pages.

My code so far is

 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);

        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゃ懵逼小萝莉 2024-10-29 02:52:31

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

示例代码在这里:
http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

Don't use RenderObject, instead use RenderDocument and pages will be created automatically as needed.

Sample code here:
http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

预谋 2024-10-29 02:52:31

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

There is no way to automatically create new pages based on text size, when you are using the Mix of PDFSharp and MigraDoc, as it is in the question. The only solution is to use only MigraDoc with its RenderDocument method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文