Murray,

I think your analysis is wrong --- the second imported document does not 
overwrite the first one. Actually you import pages 1 through 4 of the first 
document onto one page of the target, and then you want to import pages 1 and 2 
of the second document onto a second page of the target but due to using reader 
again instead of reader2 you actually do this with pages of the first document 
again.

So you should change your code to do a document.newPage() after each 
cb.addTemplate() and then use reader2 when importing from import2.pdf.

BTW, you request a second PdfContentByte object cb2 (which you actually do not 
use). As mentioned in the JavaDocs you aren't required to do that, all such 
instances returned by the same PdfReader are the same.

Michael.

--------------------------------------------------------------------------------
From: Murray Waters [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 24, 2008 7:19 AM
To: itext-questions@lists.sourceforge.net
Subject: [iText-questions] concatenating more than 1 pdf to the end of adocument


Hi,

I'm trying to concatenate 2 pdfs to the end of an existing document that I have 
built as per the itext way (using Paragraphs, etc). The problem is that the 
second imported document is being overridden starting at the same place as the 
first. So in the case below there are 2 pages of jumbled text (since the first 
document is 4 pages and the second is 2 pages).

Was wondering if anyone can help? 

        //document already has several pages in it (built using Itext)
        //the first imported document
    document.newPage();
    
 
    String urlStr = urlRoot  + "/pdf/import1.pdf";
    PdfReader reader  =new PdfReader(urlStr);
    PdfContentByte cb = writer.getDirectContent();
    
    PdfImportedPage page1 = writer.getImportedPage(reader, 1);
    cb.addTemplate(page1, 1, 0, 0, 1, 0, 0);
    PdfImportedPage page2 = writer.getImportedPage(reader, 2);
    cb.addTemplate(page2, 1, 0, 0, 1, 0, 0);
    PdfImportedPage page3 = writer.getImportedPage(reader, 3);
    cb.addTemplate(page3, 1, 0, 0, 1, 0, 0);
    PdfImportedPage page4 = writer.getImportedPage(reader, 4);
    cb.addTemplate(page4, 1, 0, 0, 1, 0, 0);
    
    //the second imported document
    document.newPage();

    String urlStr2 = urlRoot  + "/pdf/import2.pdf";
    PdfReader reader2  =new PdfReader(urlStr);
    
    PdfContentByte cb2 = writer.getDirectContent();
    PdfImportedPage page5 = writer.getImportedPage(reader, 1);
    cb.addTemplate(page5, 1, 0, 0, 1, 0, 0);
    PdfImportedPage page6 = writer.getImportedPage(reader, 2);
    cb.addTemplate(page6, 1, 0, 0, 1, 0, 0);


-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: 
http://www.gmx.net/de/go/multimessenger

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to