c# 使用iTextSharp 生成pdf demo
时间: 2024-12-28 18:31:29 浏览: 22
在C#中,使用iTextSharp库是一个常见的操作,可以创建PDF文档。以下是简单的iTextSharp生成PDF的Demo示例:
```csharp
using iTextSharp.text;
using iTextSharp.text.pdf;
// 创建一个新的PDF文档
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream("output.pdf", FileMode.Create));
// 打开文档
document.Open();
// 添加内容到文档
Paragraph paragraph = new Paragraph("Hello, this is an example PDF generated using iTextSharp.");
document.Add(paragraph);
// 关闭段落
document.Close();
```
在这个例子中,我们首先创建了一个新的`Document`对象,并通过`PdfWriter`指定输出文件路径。然后打开文档,添加一个包含文本的`Paragraph`,最后关闭文档。
阅读全文
相关推荐


















