开发者

How to preview pdf with itext and asp mvc

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜