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