环境
C# 2008 Express Edition,Windows Forms,iTextSharp 5.4.0。
我将iTextSharp.dll放在我的项目的bin
文件夹中,在项目中添加了对它的引用,使用了命名空间using iTextSharp
、iTextSharp.text
和iTextSharp.text.pdf
,并尝试了以下代码块,但没有创建任何内容且没有错误信息。
这是第一个代码块:
Document doc1 = new Document();
string path = "C:/Temp/Testing";
PdfWriter.GetInstance(doc1, new FileStream(path + "first.pdf", FileMode.Create));
doc1.Open();
doc1.Add(new Paragraph("Test"));
doc1.Close();
这是第二个区块:
FileStream fs = new FileStream("C:\\Temp\\Testing" + "Test.pdf", FileMode.Create);
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
doc.Open();
doc.Add(new Paragraph("Hello"));
doc.Close();
writer.Close();
fs.Close();