gpt4 book ai didi

vb.net - itextsharp 生成 PDF 到客户端浏览器 : (Vb.net)

转载 作者:行者123 更新时间:2023-12-04 16:21:32 24 4
gpt4 key购买 nike

我目前正在尝试使用 .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

最佳答案

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

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

关于vb.net - itextsharp 生成 PDF 到客户端浏览器 : (Vb.net),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6247583/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com