Reputation: 466
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:
Upvotes: 3
Views: 1304
Reputation: 154
Try creating a Paragraph and use the KeepTogether
Paragraph p;
p.Format.KeepTogether = true;
p.AddFormattedText(richTextBox2.Text);
Upvotes: 1