Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » iText »

[iText-questions] Problem merging pdf files

Franco Biaggi

2005-06-04


Hi,
I have problems merging some pdf files containing interative forms.
In the first step i created and fill the single pds files.
This are ok stored with the variables.
In the second step I will merge these files in a single one pdf file.

The problem is that the filled fields are present only on the last page
of the new document, in all the previous pages are blank.

Any help ?
Thanks in advance.

The merge method:

  /**
  * Merge pdf's documents
  *
  * @param pdfs The files to be merged
  */
  public PDFEditor( String[] pdfs ) {
    try {
       int pageOffset = 0;
       ArrayList master = new ArrayList( );
       int f = 0;

       // Create a temp file
       File fileName = new File( pdfs[ 0 ] );
       File file = File.createTempFile( Tools.removeFileExtension(
fileName.getName( ) ) + "_", ".pdf" );
       resultPdfFileName = file.getAbsolutePath( );

       String outFile = resultPdfFileName;
       Document document = null;
       PdfCopy writer = null;
       while ( f < pdfs.length ) {
          // Create a reader for a certain document
          PdfReader reader = new PdfReader( pdfs[ f ] );
          reader.consolidateNamedDestinations( );
          // Retrieve the total number of pages
          int n = reader.getNumberOfPages( );
          pageOffset += n;

          if ( f == 0 ) {
            // Step 1: creation of a document-object
            document = new Document(
reader.getPageSizeWithRotation( 1 ) );
            // Step 2: create a writer that listens to the document
            writer = new PdfCopy( document, new
FileOutputStream( outFile ) );
            // Step 3: open the document
            document.open( );
          }

          // Step 4: add content
          PdfImportedPage page;
          for ( int i = 0; i < n; ) {
            ++i;
            page = writer.getImportedPage( reader, i );
            writer.addPage( page );
          }

          PRAcroForm form = reader.getAcroForm( );
          if ( form != null ) {
            writer.copyAcroForm( reader );
          }

          f++;
       }

       if ( master.size( ) > 0 ) {
          writer.setOutlines( master );
       }

       // Step 5: close the document
       document.close( );
    } catch ( Throwable th ) {
       Tools.handleException( th );
    }
  }

--
-----------------------------------------------------------------------------
*** This messages was scanned for malicious contents ***
-----------------------------------------------------------------------------
Franco Biaggi
CH-6807 Taverne




-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions
©2008 junlu.com - Jax Systems, LLC, U.S.A.