Itextsharp generates PDF in a client browser: (Vb.net)

I'm currently trying to do itextsharp to create a PDF file in a browser using the .NET framework .. and yes, I use VB.net instead of C # here ...

I already compiled everything, and this is not a mistake. What causes the browser not to send me the result in pdf format? Interestingly, I forgot something?

Source:

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
+3
source share
2 answers
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename=FileName.pdf");

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

+2
source

Response.ContentType = "pdf / application"

I think you have it in the opposite direction. Must beapplication/pdf

0

All Articles