roquegil, roquegil wrote > I would to catch some existing information in a specific area, and move it > to the right. > > ... > > At this moment I've found one solution which is not ideal but should > works.
A good generic solution is difficult indeed. Even though the content to move visually probably is an obvious unit, the drawing operations for it may not be; they may be spread over the page content stream, maybe some parts even are to be found in some inner xobjects, there can even be single drawing operations drawing both stuff to move and other stuff not to move. On the other hand, though, you can make use of clipping paths, first drawing the whole page at its original position with a clipping path hiding the original area, and then drawing the whole page again moved as the area shall shift, with a clipping path only allowing drawings in the target area. E.g.: public void copyWithMovedRect(PdfReader source, int pageNr, PdfWriter target) throws DocumentException { PdfImportedPage page = target.getImportedPage(source, pageNr); PdfContentByte directContent = target.getDirectContent(); Rectangle pageRect = target.getPageSize(); directContent.saveState(); // hiding this original area directContent.rectangle(pageRect.getLeft(), pageRect.getBottom() + 650, 300, 100); // out of this whole page directContent.rectangle(pageRect.getLeft(), pageRect.getBottom(), pageRect.getWidth(), pageRect.getHeight()); directContent.eoClip(); directContent.newPath(); // draw page at original position directContent.addTemplate(page, pageRect.getLeft(), pageRect.getBottom()); directContent.restoreState(); // showing this shifted area directContent.rectangle(pageRect.getLeft() + 300, pageRect.getBottom() + 650, 300, 100); directContent.eoClip(); directContent.newPath(); // draw page shifted directContent.addTemplate(page, pageRect.getLeft() + 300, pageRect.getBottom()); } This puts the indicated page from the source PdfReader into the current page of the target PdfWriter with the area moved. There are some drawbacks to this solution, too: * I use a PdfWriter and its getImportedPage method. Thus, all interactive feature (annotations, e.g. form fields) are lost. * The content by the clipping paths is still there, merely invisible. In case of text this means that text extraction (including copy&paste) will see all text twice. Regards, Michael -- View this message in context: http://itext-general.2136553.n4.nabble.com/How-to-move-some-text-in-an-existing-PDF-from-left-to-right-tp4659854p4659859.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/13534_NeoTech _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php