Itextsharp 5.4.4 CopyAcroForm no longer exists

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.

5.4.4 CopyAcroFormno longer exists under PdfCopyor elsewhere - what's the alternative?

+4
source share
3 answers

Read the iText 5.4.4 Release Notes . Now you can use PdfCopyto combine PDF files containing AcroForm forms using the method addDocument(). This method is much better than the method copyAcroForm(), since it also preserves the roots of the structured tree. This is important if your forms become available (see Section 508 or the PDF / UA standard).

+14

AddDocument() - . , PDF SQL- asp.net. document.Close() .

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();
+1

It looks like you also need to call .SetMergeFields () or it will not work:

reader = new PdfReader(path);
using (var document = new Document(reader.GetPageSizeWithRotation(1))) {
    using (var outputStream = new FileStream(...)) {
        using (var writer = new PdfCopy(document, outputStream)) {
            writer.SetMergeFields();
            document.Open();

            //all pages:
            writer.AddDocument(reader);
            //Particular Pages:
            //writer.AddDocument(reader, new List<int> { pageNumber });
        }
    }
}
0
source

All Articles