Does the field you have on your page three happen to share a name with a 
field on any of the other pages? This may be an elementary question, but 
it's the first thing I thought of.

Below is a class I used to combine documents, you may find it helpful.

Cheers,
Brian

public class ConCat2DocsWithFields {

        public static void main(String[] args) throws IOException,
                        DocumentException {
                System.out.println("Printing PDF file ..");

                Document document = new Document();
                PdfCopyFields copy = new PdfCopyFields(new 
FileOutputStream(
                                "c:\\dxl\\renderOut1.pdf"));
                document.open();
                PdfReader reader1 = new 
PdfReader("c:\\dxl\\PersonDevice.pdf");
                PdfReader reader2 = new 
PdfReader("c:\\dxl\\PersonDevice1.pdf");
                copy.addDocument(reader1);
                copy.addDocument(reader2);
                copy.close();
                document.close();

                System.out.println("Done!");
        }

}

Brian Moore
Application Developer

1245 Bridgestone Blvd
LaVergne, TN 37086
(615) 259-5840 - Direct




From:   "Tolting Colt Acres, Inc." <toltingcoltac...@cox.net>
To:     <itext-questions@lists.sourceforge.net>
Date:   04/24/2013 11:47 AM
Subject:        [iText-questions] problem appending PDF files



I have a problem appending a PDF file containing form fields to another 
PDF without losing the form fields. I have files which illustrate this 
issue.
 
I am using iTextSharp-5.3.0 (I tried upgrading to iTextSharp-5.4.0 but 
other code in my application broke, so I had to continue to use this 
version.)
 
I have two PDFs with form fields which I populate independently. 
 
www.dropbox.com/s/x2lk6h6nz0ocurl/Page1%262.pdf
www.dropbox.com/s/za4r79ag55qat2a/Page3.pdf
 
I then use the following code to combine the files:

                // Assemble PDFs into one large file
 
                MemoryStream msFinal = new MemoryStream();
                using (FileStream fs = File.Open(_pdfFile, FileMode.Open))
                {
                      msFinal.SetLength(fs.Length);
                      fs.Read(msFinal.GetBuffer(), 0, (int)fs.Length);
                      fs.Close();
                }
               msFinal.Position = 0;
                File.Delete(_pdfFile);
 
                iPage = 3;
                pdfReader = new iTextSharp.text.pdf.PdfReader(msFinal);
                PdfStamper pdfFinal = new PdfStamper(pdfReader, new 
FileStream(_pdfFile, FileMode.Create));
                foreach (String _pdfout in _pdfs)
                {
                    if (_pdfout != _pdfFile)
                    {
                        MemoryStream ms = new MemoryStream();
                        using (FileStream fs = File.Open(_pdfout, FileMode
.Open))
                        {
                            ms.SetLength(fs.Length);
                            fs.Read(ms.GetBuffer(), 0, (int)fs.Length);
                            fs.Close();
                        }
                        ms.Position = 0;
                        PdfReader pdfReader3 = new iTextSharp.text.pdf.
PdfReader(ms);
                        pdfFinal.InsertPage(iPage, 
pdfReader.GetPageSize(1));
                        pdfFinal.ReplacePage(pdfReader3, 1, iPage);
                        pdfReader3.Close();
                        ms.Close();
                        iPage++;
                    }
                }
                try
                {
                    pdfFinal.Close();
                }
                catch { }
                pdfReader.Close();
 
The result is this file:

www.dropbox.com/s/b8hkkkav76zegwq/Page1%262%263.pdf
 
Basically, the form fields are correctly populated from the first file, 
but when I use replacepage to copy the contents of the 3rd page, I do not 
get the form fields at all on the page 3.
 
Not quite sure what I am doing wrong.
 
I have found if I create Page 3 with:

                    pdfFinal.FormFlattening = true;
                    pdfFinal.FreeTextFlattening = true;
                    pdfFinal.SetFullCompression();
 
Then the data will, in fact, show up. However, I really need to have the 
form fields intact for further editing by the user.
 
Hopefully I?ve explained this well? Any help on this issue would be 
appreciated, I really need to consolidate the files into one large PDF 
without losing the contents of the 3rd page. If there is a different 
approach to appending the files together, a pointer to an example would 
likewise be appreciated.
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring 
service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a 
reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

<<image/jpeg>>

------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to