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
 
Page rotation and rearrangement (4 in 1) at the same time

Page rotation and rearrangement (4 in 1) at the same time

2006-07-25       - By Werner Lehmann

 Back
Hi,

I have to to do some postprocessing on an existing pdf (created by iText):

1. rotate certain pages by 180 degress
2. combine 4 pages in 1

Both tasks could be solved with the list archives and the tutorial.
However, somehow I cannot rotate first, then combine 4 in 1: the result
does not have rotated pages, just as if the rotation step would have
been omitted. I have put each task into a separate method:

>   private void rotatePages(InputStream is, OutputStream os) throws
IOException, DocumentException
>   {
>     PdfReader reader = new PdfReader(is);
>     int relativePage;
>     for (int i = 1; i <= reader.getNumberOfPages(); i++)
>     {
>       relativePage = ((i - 1) % 4) + 1;
>       if (relativePage == 2 || relativePage == 3)
>         reader.getPageN(i).put(PdfName.ROTATE, new PdfNumber(180));  
>     }
>     PdfStamper stp = new PdfStamper(reader, os);
>     stp.close();
>   }

>   private void arrangePages(InputStream is, OutputStream os)
>       throws DocumentException, IOException
>   {
>     PdfReader reader = new PdfReader(is);
>     int pageCount = reader.getNumberOfPages();
>     Rectangle pageSize = reader.getPageSize(1);
>     float width = pageSize.width();
>     float height = pageSize.height();
>     float subpageWidth = width / 2;
>     float subpageHeight = height / 2;
>
>     Document document = new Document(pageSize, 50, 50, 50, 50); // TODO don't
use hardcoded margins
>     PdfWriter writer = PdfWriter.getInstance(document, os);
>
>     document.open();
>     PdfContentByte cb = writer.getDirectContent();
>     PdfImportedPage page;
>     int i = 1;
>     while (i <= pageCount)
>     {
>       document.newPage();
>       for (int y = 1; y >= 0 && i <= pageCount; y--)
>         for (int x = 0; x < 2 && i <= pageCount; x++, i++)
>         {
>           page = writer.getImportedPage(reader, i);
>           cb.addTemplate(page, .5f, 0, 0, .5f, x * subpageWidth, y *
subpageHeight);
>         }
>     }
>     document.close();
>     writer.close();
>   }

I suppose that the rotation tag or option is lost when the pages are
reread and rearranged. What can I do about this?

Werner


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