【问题标题】:itextsharp generating PDF into client browser: (Vb.net)itextsharp 生成 PDF 到客户端浏览器:(Vb.net)
【发布时间】:2011-09-09 00:11:21
【问题描述】:

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

我已经编译了所有内容,没有错误。 是什么让浏览器没有向我发送 pdf 结果? 我想知道我是否忘记了什么?

源代码:

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

【问题讨论】:

  • application/pdf,而不是相反。

标签: vb.net visual-studio itextsharp


【解决方案1】:

Response.ContentType = "pdf/应用程序"

我认为你有倒退。应该是application/pdf

【讨论】:

    【解决方案2】:
    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "inline; filename=FileName.pdf");
    

    如果您希望它在浏览器中显示 PDF,您可能需要使用 inline 而不是 attachment。否则它只会提供 PDF 作为文件下载。

    【讨论】:

      猜你喜欢
      • 2012-05-14
      • 2016-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多