简体   繁体   中英

PdfSharp: dynamic generating document

I got the following code for simply adding two textboxes-contents into a pdf-file:

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

        }
    }
}

How can i detect if the second paragraph shows up from the first page to the second page? In this case i want to put the second paragraph on the second page only.

My english is not the best. Maybe my " paint-skills " are a better help to describe the problem: 当前和期望的情况

Try creating a Paragraph and use the KeepTogether

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM