2011-06-06 38 views
3

我目前正在尝试使用.NET框架生成PDF文件到浏览器中的itextsharp ..是的,我在这里使用VB.net而不是C#。 ..itextsharp生成PDF到客户端浏览器:(Vb.net)

我已经编译好了一切,没有错误。 是什么让浏览器没有向我发送PDF结果? 我不知道我是否忘记了一些东西?

源代码:

Private Sub createPDF() 

    Using ms As New MemoryStream() 

     Dim document As New Document(PageSize.A4, 25, 25, 30, 30) 
     Dim writer As PdfWriter = PdfWriter.GetInstance(document, ms) 
     document.Open() 
     document.Add(New Paragraph("Hello World")) 
     document.Close() 

     writer.Close() 
     Response.ContentType = "pdf/application" 
     Response.AddHeader("content-disposition", "attachment;filename=First PDF document.pdf") 

     Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length) 
    End Using 

End Sub 
+0

'application/pdf',而不是其他方式。 – 2011-06-06 03:58:34

回答

0

Response.ContentType = “PDF /应用”

我觉得你有倒退。应该是application/pdf

+0

雅我已经改变了。谢谢乔尔! :d – gumuruh 2011-06-07 02:56:52

2
Response.ContentType = "application/pdf"; 
Response.AddHeader("Content-Disposition", "inline; filename=FileName.pdf"); 

如果你希望它显示在浏览器中的PDF,你可能希望使用在线而不是附件。否则,它只会提供PDF作为文件下载。

相关问题