Thanks Ning Zhao. My problem was fixed by this peace of code: PdfReader reader = new PdfReader(sciezkaout + pliki[0]); PdfCopy copy = new PdfCopy(document, new FileOutputStream(sciezkaout + "sklejony.pdf")); document.open(); Rectangle crop = reader.getCropBox(1); PdfDictionary pagedict; for (String aPliki : pliki) { reader = new PdfReader(sciezkaout + aPliki); int nu_pages = reader.getNumberOfPages(); for (int j = 1; j <= nu_pages; j++) { if (crop.getWidth() != reader.getCropBox(j).getWidth() && crop.getHeight() != reader.getCropBox(j).getHeight()) { pagedict = reader.getPageN(j); pagedict.put(PdfName.MEDIABOX, new PdfRectangle(15, 0, 582, 820)); } copy.addPage(copy.getImportedPage(reader, j)); } } document.close();
Fortunetly i haven't had use your code, but thanks anyway. Pozdrawiam, Paweł Gawędzki -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ning Zhao Sent: Thursday, April 10, 2008 3:01 PM To: Post all your questions about iText here Subject: Re: [iText-questions] is it possible to grab and move whole content of pdf ? Hi Pawel, here is my code to centre the content while changing the page size. ----------------------- code -------------------------------------- // urx is the upper right x of the target page size // ury is the upper right y of the target page size public void changePageSize(float urx, float ury, String outputURI) { Rectangle oldCropbox = reader.getCropBox(1); float oldCWidth = oldCropbox.getWidth(); float oldCHight = oldCropbox.getHeight(); float deltaW = (float) (urx - oldCWidth); float deltaH = (float) (ury - oldCHight); if (log.isLoggable(Level.FINE)) { log.fine("delta width: " + deltaW); log.fine("delta hight: " + deltaH); } float oldLlx = 0f; float oldLly = 0f; float oldUrx = oldCWidth; float oldUry = oldCHight; float newLlx = oldLlx; float newLly = oldLly; float newUrx = oldUrx; float newUry = oldUry; if (deltaW > 0) { newLlx = -deltaW / 2 + oldLlx; // 0 is the original llx newUrx = deltaW / 2 + oldUrx; if (log.isLoggable(Level.FINE)) { log.fine("new llx: " + newLlx); log.fine("new Urx: " + newUrx); } } if (deltaH > 0) { newLly = -deltaH / 2 + oldLly; // 0 is the original lly newUry = deltaH / 2 + oldUry; if (log.isLoggable(Level.FINE)) { log.fine("new lly: " + newLly); log.fine("new ury: " + newUry); } } Rectangle pageSize = new Rectangle(newLlx, newLly, newUrx, newUry); PdfDictionary dict = reader.getPageN(1); dict.put(PdfName.CROPBOX, new PdfRectangle(pageSize)); dict.put(PdfName.MEDIABOX, new PdfRectangle(pageSize)); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputURI)); stamper.close(); } ---------------------------- code ---------------------------------- in my case I was enlarging the page size. You may need to adjust the code to fit your need. This code works for me, but I'd like very much to know eleganter solution. Best Regards, Ellen N. Zhao precyz schrieb: > I created one pdf from few pdfs useing this code: > > PdfReader reader = new PdfReader(sciezkaout + pliki[0]); > Rectangle page_size = PageSize.A4; > PdfCopy copy = new PdfCopy(document, new > FileOutputStream(sciezkaout + "sklejony.pdf")); > document.open(); > Rectangle crop = reader.getCropBox(1); > PdfDictionary pagedict; > for (String aPliki : pliki) { > reader = new PdfReader(sciezkaout + aPliki); > int nu_pages = reader.getNumberOfPages(); > for (int j = 1; j <= nu_pages; j++) { > if (crop != reader.getCropBox(j)) { > pagedict = reader.getPageN(j); > pagedict.put(PdfName.CROPBOX, new > PdfRectangle(crop)); > } > copy.addPage(copy.getImportedPage(reader, j)); > } > } > document.close(); > > I got document that has few pages with content moved to much right. So > i want move this content to left side of document. Is it possible to > grab and move whole content of pdf to other position. If it is then how. > > Pawel Gawedzki > -- HaCon Ingenieurgesellschaft mbH Lister Str. 15 30163 Hannover Germany/Deutschland Tel. +49 511 33699-363 Fax. +49 511 33699-99 Email: [EMAIL PROTECTED] http://www.hacon.de Registry Court/Amtsgericht Hannover HRB 1712 Managing Directors/Geschäftsführer: Michael Frankenberg, Dr.-Ing. Marian Gaidzik, Dr.-Ing. Werner Kretschmer, Werner Sommerfeld, Dr.-Ing. Volker Sustrate, Peter Talke ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Do you like iText? Buy the iText book: http://www.1t3xt.com/docs/book.php Or leave a tip: https://tipit.to/itexttipjar ------------------------------------------------------------------------------ Skandia Życie Towarzystwo Ubezpieczeń S.A. ul. Cybernetyki 7, 02-677 Warszawa Sąd Rejonowy dla m.st. Warszawy, XIII Wydział Gospodarczy Krajowego Rejestru Sądowego Nr KRS 0000056463, Regon: 016003836, NIP: 951-19-33-418 wysokość kapitału zakładowego: 46.000.000,00 PLN wysokość kapitału wpłaconego: 46.000.000,00 PLN ------------------------------------------------------------------------------ ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Do you like iText? Buy the iText book: http://www.1t3xt.com/docs/book.php Or leave a tip: https://tipit.to/itexttipjar