0

I have problems to fill a PDF file, when I try to open the file is damaged.

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

Previously was using filestream, generated either files, but I need to have you with MemoryStream for my website

4

1 回答 1

0

PDF 已损坏,因为您忘记关闭PdfStamper实例。Close'()在操作序列之后使用该方法SetField()

于 2013-07-23T11:15:53.550 回答