【问题标题】:PdfSharp: dynamic generating documentPdfSharp:动态生成文档
【发布时间】:2016-06-20 07:34:10
【问题描述】:

我得到以下代码,只需将两个文本框内容添加到 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”可以更好地帮助描述问题:

【问题讨论】:

    标签: c# dynamic pdfsharp


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多