Skip to main content
Skip table of contents

How to move the content inside a rectangle inside an existing PDF? | iText 5 PDF Development Guide

My goal is to move text in a PDF around, which is within a certain rectangular area. All content matching the area in the original PDF should be shifted somewhat in the x and y direction. I have no influence on how the PDFs are created and I can accept a solution that only vaguely works.

Posted on StackOverflow on Feb 6, 2015 by tom_ink

Suppose that you have a PDF document like this:

Original PDF

Original PDF

I also have the coordinates of a rectangle: new Rectangle(100, 500, 200, 600); and an offset: move everything in that rectangle 10 points to the left and 2 points to the bottom, like this:

Manipulated PDF

Manipulated PDF

That is fairly easy to achieve. Take a look at the CutAndPaste example:

##GITHUB:https://github.com/itext/i5js-sandbox/blob/master/src/main/java/sandbox/merge/CutAndPaste.java|39-73##

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.