3
環境
C#2008 Express Edition,Windows Forms,iTextSharp 5.4.0。iTextSharp無法在Winforms項目中運行
我把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();
在C以外的任何其他驅動器上嘗試您的代碼。 – Shaharyar
您可能正在尋找文件c:\ Temp \ Testing \ Test.pdf。文件名似乎保存到C:\ Temp \ TestingTest.pdf「 – Crispy
在C:\\ Temp \\結尾處添加\\測試完成了。 – KFP