In the release notes of iText 5.4.4 it says:
From now on you can now merge forms and preserve the tagged PDF
structure when using the addDocument() method in PdfCopy. At the same
time, we've deprecated PdfCopyFields.*
I try to merge multiple pdf documents into one pdf document. If one of these documents is a pdf form with acroFields, those fields will be invisible in the output document. This is the case when I use the addDocument() method in PdfCopy.
When I use the addDocument() method in PdfCopyFields it works fine. PdfCopyFields is deprecated in iTextSharp, but is PdfCopy working correctly? There is another reason not to use PdfCopyFields (from "iText in Action":
Don’t use PdfCopyFields to concatenate PDF documents without form
fields. As opposed to concatenating documents using PdfCopy, Pdf-
CopyFields needs to keep all the documents in memory to update the
combined form. This can become problematic if you’re trying to
concatenate large documents.
This is the code I use:
public static void MergePdfs4()
{
var f1 = @"C:UserspaulusjDownloadsOoPdfFormExampleFilled.pdf";
var f2 = @"c:GEODANworkEV_Original.pdf";
using (
Stream outputPdfStream = new FileStream("combined4.pdf ", FileMode.Create, FileAccess.Write,
FileShare.None))
{
var document = new Document();
var copy = new PdfCopy(document, outputPdfStream);
document.Open();
copy.AddDocument(new PdfReader(f1));
copy.AddDocument(new PdfReader(f2));
copy.Close();
}
}
The strange thing is that when I copy EV_Original.pdf using Adobe Reader "Save As", the copy is merged (almost) correctly. So in the output pdf I can see the form fields.
When I use this code:
public static void MergePdfs3()
{
var f1 = @"C:UserspaulusjDownloadsOoPdfFormExampleFilled.pdf";
var f2 = @"c:GEODANworkEV_Original.pdf";
using (Stream outputPdfStream = new FileStream("combined3.pdf ", FileMode.Create, FileAccess.Write,
FileShare.None))
{
var copy = new PdfCopyFields(outputPdfStream);
copy.AddDocument(new PdfReader(f1));
copy.AddDocument(new PdfReader(f2));
copy.Close();
}
}
It works fine. But in this code PdfCopyFields is used.
The pdfs used can be found here:
Example.pdf
EV_Original.pdf
Is there something wrong with EV_Original.pdf, or is PdfCopy not implemented correctly?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…