Hi,

I have 200+ existing pdf documents that I would like to combine into one pdf 
file. The first couple of pages should be a table of contents that would allow 
the user to click on a name and go to the correct page.

My plan was to use PdfStamper on each pdf file to place a new page number on 
each page, then use PdfCopy to merge the documents together.

What I need help with is how to create the table of contents.


table of contents example:
 
 001.pdf     page 3 - 5   (Click here to go to page 3)
 002.pdf     page 6 - 12  (Click here to go to page 6)
 ...
 200.pdf     page 535-537 (Click here to go to page 535)

My first attempt was to create the table of contents from the PdfCopy document. 
I couldn't figure out where the content was going. It didn't appear in the 
output document.

  if (f == 0) {
    document = new Document(reader.getPageSizeWithRotation(1));
    writer = new PdfCopy(document, new FileOutputStream(outFile));
    document.open();
    document.add(new Paragraph("001.pdf Page 3-5")); // never made it to the pdf
    document.add(new Paragraph("002.pdf Page 6-12"));
    document.newPage();
  }
  for (int i = 0; i < n; ) {
     ++i;
     page = writer.getImportedPage(reader, i);
     writer.addPage(page);
  }


My second attempt was to create the table of contents as a separate document 
using Anchors then merge it later. I would always get an exception on the 
document.close stating the destination could not be found.

// create table of contents pdf

        document.add(new Paragraph("001.pdf Page 3-5"));
        Anchor anchor2 = new Anchor("Go to the internal link"); 
        anchor2.setReference("#" + "a.pdf");
        document.add(anchor2);

would throw

Exception in thread "main" java.lang.RuntimeException: The name 'a.pdf' has no 
local destination.
    at com.lowagie.text.pdf.PdfWriter.addLocalDestinations(PdfWriter.java:1726)
    at com.lowagie.text.pdf.PdfDocument.close(PdfDocument.java:926)
    at com.lowagie.text.Document.close(Document.java:520)


How do I add Paragraphs with local goto action then merge other pdf documents 
using PdfCopy?







-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7412&alloc_id=16344&op=click
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to