In version 5.4.2 of itextsharp I was able to use: (fragment in VB)
Dim pdfWriter As iTextSharp.text.pdf.PdfCopy
pdfwriter = New iTextSharp.text.pdf.PdfCopy(outputPDFDocument, New FileStream(destfname, FileMode.Create))
pdfWriter.CopyAcroForm(reader)
to copy a form from one document to another.
In 5.4.4 CopyAcroForm
is no longer there under PdfCopy
or anywhere else - what is the alternative?
Please read the release notes for iText 5.4.4. It is now possible to use PdfCopy
to merge PDFs containing AcroForm forms by using the addDocument()
method. This method is much better than the copyAcroForm()
method as it also preserves the structured tree root. This is important if your forms are made accessible (cf Section 508 or the PDF/UA standard).
AddDocument() method is cool. Here is my code that read and merge multiple PDFs from SQL server in asp.net . document.Close() is required to flush the content to memory stream.
enter code here
Document document = new Document();
MemoryStream output = new MemoryStream();
PdfCopy writer = new PdfCopy(document, output); // Initialize pdf writer
writer.SetMergeFields();
document.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
PdfReader reader = new PdfReader((Byte[])dr["ImageFile"]);
writer.AddDocument(reader);
}
dr.Close();
document.Close();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With