Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
JSP - A mailing list about Java Server Pages specification and reference
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
PdfWriter.reorderPages failure

PdfWriter.reorderPages failure

2006-07-27       - By Scott Tomer

 Back
Reply:     1     2  

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

<pre>I am trying to reorder the pages in a PDF document after adding some <br
>extra pages.  The following code fails saying that the integer array <br>must
be the same size as the number of pages in the document.  When I <br>
step into the code, I see that it believes that the number of pages in <br>the
PdfWriter is 0 (zero).<br><br>Help?<br><br>---code---<br>public boolean go
(String pdfFile, String newFile, boolean duplexLate) {<br>   try {<br>
        PdfStamper stamp = null;<br>         PdfReader reader = new PdfReader
(pdfFile);<br>         int pageCount = reader.getNumberOfPages();<br><br>        
stamp = new PdfStamper(reader, new FileOutputStream(newFile));<br>          if
(duplexLate) {
<br>              //Add an extra page after the address page<br>            
stamp.insertPage(2, PageSize.LETTER);<br>              pageCount++;<br>          
}<br>          int mod = pageCount % 2;<br>          if (mod != 0) { //not even
number of pages, add one
<br>             stamp.insertPage(pageCount+1, PageSize.LETTER);<br>          
  pageCount++;<br>          }<br>          int[] newOrder = new int[pageCount];<br>
         for (int i=1, j=0; i&lt;pageCount;i+=2, j+=2) {<br>             newOrder[j
] = i+1;
<br>             newOrder[j+1] = i;<br>          }<br>          stamp.getWriter()
.reorderPages(newOrder);<br>          stamp.close();<br>          return true;<br>
  }<br>         catch (Exception de) {<br>     return false;<br>   }<br>
}<br>---end code---<br><br>Thanks,<br>Scott Tomer</pre>

-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
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

©2008 junlu.com - Jax Systems, LLC, U.S.A.