0
我使用MigraDoc在c#中從某些數據庫表中生成PDF文件。防止MigraDoc中的段落分割
我的主要問題是一些我添加了一段,他們不能被安裝到的當前頁面,所以被劃分到的下一個頁面,如何預防? 我希望他們在一個頁面(當前頁面或下一頁)。
Document doc = new Document();
Section section = doc.AddSection();
Paragraph paragraph = section.AddParagraph();
paragraph.AddLineBreak();
paragraph.AddLineBreak();
paragraph.AddLineBreak();
paragraph.Format.TabStops.ClearAll();
paragraph.Format.TabStops.AddTabStop("16cm", TabAlignment.Right, TabLeader.Lines);
paragraph.AddTab();
for (int i = 0; i < 20; i++)
{
Paragraph paragraphBody = paragraph.Section.AddParagraph();
FormattedText ft = paragraphBody.AddFormattedText("This is a title", TextFormat.Bold);
ft.Italic = true; ft.Font.Size = 11;
ft.Font.Color = Color.FromRgbColor((byte)255, Color.Parse("0x1E9BC6")); //equal to rgb(30, 155, 196);
ft.AddLineBreak();
//--detail:---adding text---------------------------------
String DetailText = "This is detail. This is detail. This is detail.This is detail.This is detail.This is detail.This is detail.This is detail. This is detail. This is detail. This is detail. This is detail. This is detail. This is detail. This is detail. This is detail. ";
FormattedText ftdet;
ftdet = paragraphBody.AddFormattedText(DetailText, TextFormat.NotBold);
ftdet.Font.Size = 10;
ftdet.Font.Name = "Arial";
ftdet.AddLineBreak();
ftdet.AddLineBreak();
ftdet.AddText("Event Date: " + DateTime.Now.ToString("MM/dd/yyyy h:mm tt"));
}
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);
pdfRenderer.Document = doc;
pdfRenderer.RenderDocument();
//Save the PDF to a file:
string filename = "e:\\Report" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".pdf";
pdfRenderer.PdfDocument.Save(filename);
Process.Start(filename);