> 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:
Have you checked your post-rotation output stream to ensure that it really is rotated? Making changes within a Reader is Fraught With Peril. I'm fuzzy on the details here because I've made some changes to my local build. These changes make such things possible, but I'm pretty sure they do some unpleasant things to memory usage... a typical programming tradeoff. Having said that, here goes: Any time PdfReader looks up an indirect reference, it uses the object number and fetches it from the input stream. Therefore, making changes to the object returned by reader.getPageN() doesn't mean that the PdfStamper will see those changes later. OTOH, poking about in the source shows me that there's an object cache being used, so I could easily be wrong here. Huh. Creating the PdfStamper after making your changes may have something to do with this. Anyway, there are several ways to work around this. 1) Dig around in the source for a place where you can change the page's dictionary and have it 'take'. This may include creating your PdfStamper before making the page rotation changes. 2) Change the transformation matrix in addTemplate() 3) Set the page's transformation through PdfImportedPage.setMatrix(). I'm in favor of #3 personally: // I believe this is correct, but it's off the top of my head, so 'buyer beware' page.setMatrix(-1, 0, 0, -1, page.getWidth(), page.getHeight() ); When you rotate, you're rotating around the origin, so the page ends up in the 3rd quadrant. Remember quadrants? So to rotate it 'in place', you have to move it back up to its starting location, thus the width & height translations. You'll have to wrap that setMatrix() in your 'relativePage' test from the rotation function, but you probably knew that already. Better safe than sorry and all that. The 2nd and 3rd options have the added bonus of being significantly more efficient. iText won't have to write then read an intermediate PDF. Less memory usage /and/ faster execution... who doesn't like that? --Mark Storer Senior Software Engineer Cardiff Software #include <disclaimer> typedef std::Disclaimer<Cardiff> DisCard; ------------------------------------------------------------------------- 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@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions