Use PdfReader.selectPages().
Paulo
----- Original Message -----
From: "Scott Tomer" <wstomer@(protected)>
To: <itext-questions@(protected)>
Sent: Thursday, July 27, 2006 3:05 PM
Subject: [iText-questions] PdfWriter.reorderPages failure
>I am trying to reorder the pages in a PDF document after adding some
> extra pages. The following code fails saying that the integer array
> must be the same size as the number of pages in the document. When I
> step into the code, I see that it believes that the number of pages in
> the PdfWriter is 0 (zero).
>
> Help?
>
> ---code---
> public boolean go(String pdfFile, String newFile, boolean duplexLate) {
> try {
> PdfStamper stamp = null;
> PdfReader reader = new PdfReader(pdfFile);
> int pageCount = reader.getNumberOfPages();
>
> stamp = new PdfStamper(reader, new FileOutputStream(newFile));
> if (duplexLate) {
> //Add an extra page after the address page
> stamp.insertPage(2, PageSize.LETTER);
> pageCount++;
> }
> int mod = pageCount % 2;
> if (mod != 0) { //not even number of pages, add one
> stamp.insertPage(pageCount+1, PageSize.LETTER);
> pageCount++;
> }
> int[] newOrder = new int[pageCount];
> for (int i=1, j=0; i<pageCount;i+=2, j+=2) {
> newOrder[j] = i+1;
> newOrder[j+1] = i;
> }
> stamp.getWriter().reorderPages(newOrder);
> stamp.close();
> return true;
> }
> catch (Exception de) {
> return false;
> }
> }
> ---end code---
>
> Thanks,
> Scott Tomer
>
--------------------------------------------------------------------------------
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
--------------------------------------------------------------------------------
> _______________________________________________
> iText-questions mailing list
> iText-questions@(protected)
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions