我在这里放了一段c#和iText7 PDF格式的代码。我不知道为什么它不打印3张3行的纸,因为我在每组3行的前面有一个"AddNewPage"(只打印一页9行(。你能帮我吗?谢谢。
private void button1_Click(object sender, EventArgs e)
{
var writer = new PdfWriter(@"C:PDFDirTestPDF.pdf");
var pdf = new PdfDocument(writer);
var document = new Document(pdf);
Paragraph p = new Paragraph("");
document.SetMargins(6, 0, 0, 18); //T,R,B,L
pdf.AddNewPage(); //Page 1
p = new Paragraph("Line 1 page 1");
document.Add(p);
p = new Paragraph("Line 2 page 1");
document.Add(p);
p = new Paragraph("Line 3 page 1");
document.Add(p);
pdf.AddNewPage(); //Page 2 ?
p = new Paragraph("Line 1 page 2");
document.Add(p);
p = new Paragraph("Line 2 page 2");
document.Add(p);
p = new Paragraph("Line 3 page 2");
document.Add(p);
pdf.AddNewPage(); //Page 3 ?
p = new Paragraph("Line 1 page 3");
document.Add(p);
p = new Paragraph("Line 2 page 3");
document.Add(p);
p = new Paragraph("Line 3 page 3");
document.Add(p);
document.Close();
} //End of button1_Click
我认为,您混淆了目标,将每个新的Paragraph
添加到Document
,但将新页面添加到PdfDocument
。尝试将休息时间添加到文档中。
var pdf = new Document();
PdfWriter.GetInstance(docPdf, new FileStream(<path>, FileMode.Create));
pdf.Open();
pdf.Add(new Paragraph("Line 1 page 1"));
pdf.NewPage();
pdf.Close();