开发者

How to preview pdf with itext and asp mvc

开发者 https://www.devze.com 2023-03-06 19:50 出处:网络
The following code creates a pdf that downloads after you press the link / button. How do you make it happend that the pdf opens inside the browser without the automatic download?

The following code creates a pdf that downloads after you press the link / button. How do you make it happend that the pdf opens inside the browser without the automatic download?

'
    ' GET: /PDF

    Function Index() As FileResult
        Dim filestream As Stream = generatePDF()

        HttpContext.Response.AddHeader("content-disposition", "attachment; filename=Lijstmetmensenenmiddelen.pdf")

        Return New FileStreamResult(filestream, "application/pdf")
    End Function

    Private Function generatePDF() As Stream
        '' magic will happen here
        Dim memStream As MemoryStream = New MemoryStream()
        Dim doc As New Document()
        PdfWriter.GetInstance(doc, Response.OutputStream)

        doc.AddCreationDate()

        doc.Open()

        Dim para As New Paragraph()

        para.Add("Dit is een paragrafstring balbalbalal")

        doc.Add(para)

        doc.Close()


        Return memStream
开发者_运维百科
    End Function


Found the answer on this blog : http://nickstips.wordpress.com/2011/01/17/asp-net-mvc-displaying-a-pdf-document-in-the-browser/

HttpContext.Response.AddHeader("content-disposition", "attachment; filename=Lijstmetmensenenmiddelen.pdf")

should be

HttpContext.Response.AddHeader("content-disposition", "Inline; filename=Lijstmetmensenenmiddelen.pdf")
0

精彩评论

暂无评论...
验证码 换一张
取 消