当我尝试打开文件时,我有填充PDF文件的问题。
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.pdf.parser
Imports System.Data
Imports System.IO
Public Sub FillPdf()
Dim msPDF As New MemoryStream
Dim reader As New PdfReader(Request.MapPath("~/PdfFiles/form01.pdf"))
Dim workinFolder = Environment.GetFolderPath(Environment.SpecialFolder.Recent)
Dim workinFile = Path.Combine(workinFolder, "PRES-19072013.pdf")
Dim formFiller As New PdfStamper(reader, msPDF)
Dim formFields As AcroFields
formFields = formFiller.AcroFields
formFields.SetField("Order", "01999")
formFields.SetField("datePDF", "17/07/2013")
Response.Clear()
Response.AddHeader("Content-Type", "application/pdf")
Response.AddHeader("Cache-Control", "no-cache")
Response.AddHeader("Accept-Ranges", "none")
Response.AddHeader("Content-Disposition", "attachment; filename=pres2013.pdf")
msPDF.WriteTo(Response.OutputStream)
Response.Flush()
Response.End()
End Sub
以前使用的是filestream,生成了两个文件,但是我需要为你的网站安装MemoryStream
答案 0 :(得分:0)
PDF已损坏,因为您忘记关闭PdfStamper
实例。在Close'()
操作序列之后立即使用SetField()
方法。