itextsharp将PDF生成到客户端浏览器中:(Vb.net) [英] itextsharp generating PDF into client browser: (Vb.net)

查看:229
本文介绍了itextsharp将PDF生成到客户端浏览器中:(Vb.net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用.NET框架将itextsharp生成PDF文件到浏览器中..是的,我在这里使用的是VB.net而不是C#...

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...

我已经编译了所有内容并且没有错误。
是什么让浏览器没有给我发送PDF格式的结果?
我想知道我忘记了什么吗?

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?

源代码:

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


推荐答案

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

如果您希望它在浏览器中显示PDF,您可能需要使用 inline 而不是附件。否则它只会将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.

这篇关于itextsharp将PDF生成到客户端浏览器中:(Vb.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆