Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

itextsharp 5.4.4 CopyAcroForm no longer there

Tags:

itextsharp

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?

like image 824
user3024825 Avatar asked Dec 04 '22 08:12

user3024825


2 Answers

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).

like image 77
Bruno Lowagie Avatar answered Apr 20 '23 09:04

Bruno Lowagie


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();
like image 44
David J Avatar answered Apr 20 '23 09:04

David J