代码如下:
// 创建指定纸张的PDF
public void CreatePDF2()
{
Document document = new Document(PageSize.A5.Rotate());
PdfWriter.GetInstance(document, new FileStream(Server.MapPath("~/PDF/Hello.pdf"), FileMode.Create));
document.Open();
for (int i = 0; i < 5; i++)
document.Add(new Phrase("Hello,World!"));
document.Close();
}
// 在PDF指定位置添加段落
public void CreatePDF3()
{
Document document = new Document(PageSize.A5, 36, 72, 108, 100);
PdfWriter.GetInstance(document, new FileStream(Server.MapPath("~/PDF/Hello.pdf"), FileMode.Create));
document.Open();
Paragraph paragraph = new Paragraph();
paragraph.Alignment = Element.ALIGN_BOTTOM;
for(int i=0;i<20;i++)
{
paragraph.Add("Hello World!");
}
document.Add(paragraph);
document.Close();
}
本文介绍了如何使用iText库在C#中创建带有特定页面尺寸的PDF文档,并展示了如何在文档的指定位置添加文本段落。通过示例代码,读者可以了解到创建PDF的基本步骤,包括设置页面尺寸、打开文档、添加文本等。
设置PDF纸张并在指定位置添加文字&spm=1001.2101.3001.5002&articleId=8028869&d=1&t=3&u=3ce9191763724ffcbf2301e325a5dd84)
1026

被折叠的 条评论
为什么被折叠?



