itextsharp generating PDF into client browser: (Vb.net)

人盡茶涼 提交于 2019-12-12 16:15:00

问题


I'm currently trying to make itextsharp generating PDF file into the browser using .NET framework.. and yes, I'm using VB.net instead of C# here...

I already compiled everything and it's no error. What makes the browser didn't send me the pdf result? I wonder if i forgotten something?

Source Code:

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

回答1:


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

If you want it to display the PDF in the browser you may want to use inline instead of attachment. Otherwise it will only offer the PDF as a file download.




回答2:


Response.ContentType = "pdf/application"

I think you have that backwards. Should be application/pdf



来源:https://stackoverflow.com/questions/6247583/itextsharp-generating-pdf-into-client-browser-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!