Hi,  I am trying to read in a pdf file, add some named destination then save them to a new file.

Here’s my code:

                                    int pages = reader.getNumberOfPages();

 

                                    Document document  = new Document( reader.getPageSizeWithRotation( 1 ) );

                                    PdfCopy  writer          = new PdfCopy( document, new FileOutputStream("test.pdf") );

                                    document.open();

                                    String name = “test_destination”;

 

                                    for (int i = 1; i <= pages; i++)

                                            writer.addPage(writer.getImportedPage(reader, i);

 

                                                             PdfDestination destination = new PdfDestination(PdfDestination.FITR, 0, 0, 0, 0);

                                                             PdfContentByte cb = writer.getDirectContent();

                                                             cb.localDestination(name, destination);

                                                             PdfAction.gotoLocalPage(i, destination, writer);

                                    }

                                    document.close();

I keep getting the exception at the same place for each page:

 

java.lang.IllegalArgumentException: Invalid page number 3

        at com.lowagie.text.pdf.PdfCopy.getPageReference(PdfCopy.java:359)

        at com.lowagie.text.pdf.PdfWriter.getCurrentPage(PdfWriter.java:2164)

        at com.lowagie.text.pdf.PdfDocument.localDestination(PdfDocument.java:2989)

        at com.lowagie.text.pdf.PdfContentByte.localDestination(PdfContentByte.java:2489)

 

What am I doing wrong here? Appreciate you help!

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to