gumuruh
gumuruh

Reputation: 93

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

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

Upvotes: 4

Views: 3459

Answers (2)

Pete
Pete

Reputation: 2463

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.

Upvotes: 3

Joel Coehoorn
Joel Coehoorn

Reputation: 415600

Response.ContentType = "pdf/application"

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

Upvotes: 0

Related Questions