c# - PdfSharp:动态生成文档

标签 c# dynamic pdfsharp

我得到了以下代码,用于将两个文本框内容简单地添加到 pdf 文件中:

using System;
using System.Windows.Forms;
using PdfSharp.Pdf;
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;

namespace pdfDynamic
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Creating the document
            Document document = new Document();
            Section section = document.AddSection();

            //Adding the first paragraph
            section.AddParagraph(richTextBox1.Text);

            //Adding the second paragraph
            section.AddParagraph(richTextBox2.Text);

            //Creating the document
            PdfDocumentRenderer renderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);
            renderer.Document = document;
            renderer.RenderDocument();
            string pdfFilename = string.Format("Rekla-{0:dd.MM.yyyy_hh-mm-ss}.pdf", DateTime.Now);
            renderer.PdfDocument.Save(pdfFilename);

        }
    }
}

如何检测第二段是否从第一页显示到第二页?在这种情况下,我只想将第二段放在第二页上。

我的英语不是最好的。也许我的“paint-skills”更有助于描述问题: current and desired situation

最佳答案

尝试创建一个段落并使用 KeepTogether

Paragraph p;
p.Format.KeepTogether = true;
p.AddFormattedText(richTextBox2.Text);

关于c# - PdfSharp:动态生成文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37916861/

相关文章:

c# - 从数字数组中找出所有的加减法组合

用于引用 textView 的 Android id 数组

.net - 将 PDF 与 PDFSharp 丢失表单字段相结合

pdf - 在 PdfSharp 中更改文本颜色

asp.net-mvc - ASP.NET MVC PDFsharp 生成 PDF : cannot add font

c# - 外键引用对象返回 null

c# - 如何将代码从 C# 转换为 PHP

c# - 从 IActionResult 响应中删除空值

c - 为什么我们需要动态内存分配,尽管我们可以使用可变长度数组来代替?

C - 分配动态数组后无法接受输入