簡體   English   中英

PdfSharp:動態生成文檔

[英]PdfSharp: dynamic generating document

我得到以下代碼,只需將兩個文本框內容添加到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);

        }
    }
}

如何檢測第二頁是否顯示從第一頁到第二頁? 在這種情況下,我想將第二段放在第二頁上。

我的英語不是最好的。 也許我的“ 繪畫技巧 ”是描述問題的更好幫助: 當前和期望的情況

嘗試創建段落並使用KeepTogether

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM