[英]PdfSharp: dynamic generating document
I got the following code for simply adding two textboxes-contents into a pdf-file: 我得到以下代码,只需将两个文本框内容添加到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);
}
}
}
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 尝试创建段落并使用KeepTogether
Paragraph p;
p.Format.KeepTogether = true;
p.AddFormattedText(richTextBox2.Text);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.