Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# iTextSharp在Winforms项目中不起作用 环境_C#_Winforms_Itextsharp - Fatal编程技术网

C# iTextSharp在Winforms项目中不起作用 环境

C# iTextSharp在Winforms项目中不起作用 环境,c#,winforms,itextsharp,C#,Winforms,Itextsharp,C#2008快速版,Windows窗体,iTextSharp 5.4.0 我将iTextSharp.dll放在我的projectsbin文件夹中,我在我的项目中添加了对它的引用,我使用iTextSharp、iTextSharp.text和iTextSharp.text.pdf创建了命名空间,我尝试了以下代码,但没有创建任何错误消息 这里是第一个街区: Document doc1 = new Document(); string path = "C:/Temp/Testing"

C#2008快速版,Windows窗体,iTextSharp 5.4.0

我将iTextSharp.dll放在我的projects
bin
文件夹中,我在我的项目中添加了对它的引用,我使用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();

此示例打开一个对话框,用户可以保存文件。使用代码转换器将VB代码转换为C#

Using ms As New System.IO.MemoryStream()
Using doc As New iTextSharp.text.Document(iTextSharp.text.PageSize.A4)
Using w As iTextSharp.text.pdf.PdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, ms)

Dim FileName As String = "Name.pdf"


Here create your document end close it

Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("content-disposition", "attachment;filename= " & FileName)
Response.Buffer = True
Response.Clear()
Dim bytes = ms.ToArray()
Response.OutputStream.Write(bytes, 0, bytes.Length)
Response.OutputStream.Flush()


End Using
End Using
End Using

在除C以外的任何其他驱动器上尝试您的代码。您可能正在查找文件C:\Temp\Testing\Test.pdf。文件名似乎正在保存到C:\Temp\TestingTest.pdf“在C:\\Temp\\Testing的末尾添加\\完成了此操作。我已将其转换并使用System.Web.UI添加,但响应是未登录的。这是针对windows窗体而不是Web窗体的。