I am trying to merge PDF files that contain form data. I have tried several different iTextSharp examples found here on StackOverflow, but they all result in the same behavior: the first PDF document that is merged maintains its form data, but the subsequent PDF documents lose their form data. I also tried flattening the documents before merging by using the code below, but this just results in a complete loss of all form data.
public static byte[] FlattenPdfForm(byte[] bytes)
{
PdfReader reader = new PdfReader(bytes);
using (MemoryStream stream = new MemoryStream())
{
PdfStamper stamper = new PdfStamper(reader, stream) { FormFlattening = true };
stamper.Close();
reader.Close();
return stream.ToArray();
}
}
The PDF documents I am trying to merge are returned from the UPS API. Here is an example document: http://dl.dropbox.com/u/9005746/OriginalPDF.pdf
Do you have any recommendations on how I can merge multiple PDF files like the one above into a single PDF while maintaining the form data?