1

I need to be able to specify a rectangular area on a PDF page and move the text and graphic content of that area to a new location on the same page using PDFBox. Any graphics (lines, pictures, etc) will each move as a whole unit if selected in the area.

The PDF documents being modified originate as text based PCL and are converted to PDF using a third party tool. I can answer technical questions about these documents if needed.

This Stack Overflow question is exactly what I am after but that question seems to have been abandoned before a working solution was found?

I would bounty this question if I had a few more reputation points.

If you can help with any aspect of this issue I would appreciate your assistance, thank you.

Community
  • 1
  • 1
DavesPlanet
  • 576
  • 5
  • 14
  • 1
    The reason why *that question seems to have been abandoned before a working solution* is that your task is highly non-trivial to implement. Each drawing instruction in a PDF may target an are inside your rectangle, outside it, or partially inside and partially outside. Thus, for each instruction you may have to change coordinates, manipulate the current clip path, etc (which may be complicated enough); or you might even have to somehow split the instruction for parts inside and parts outside. For drawing a line this is feasible but for drawing a letter? – mkl Jun 23 '16 at 21:33
  • You seem to not require the complication of splitting the instruction but already the mere moving can be complicated as hell. – mkl Jun 23 '16 at 21:37
  • We will only move complete units of text or graphics. It seems like we simply need to adjust the coordinates associated with a text or graphic element. There are numerous examples in the PDFBox source for modifying documents, and one demo for locating text within a certain rectangle. We should be able to locate the text elements in a rectangle and update their coordinates. I would even accept an answer to this question that only dealt with text and left the graphics as a separate problem for us to figure out. – DavesPlanet Jun 24 '16 at 15:22

1 Answers1

0

I'm not as familiar with PDFBox as I should be but any library should be able to do the following; I know the one I represent can.

Create a new blank page that's the same size as your original. Copy the content of the original to an XObject and apply that to the blank page. Add a white rectangle to the page to obscure the rectangle in question. Clip the content of the original page to the rectangle you want to "move". Create a second XObject from that. Apply it to the new page in the position you want.

If PDFBox is capable of it, Sanitize the new page to remove the hidden content under the white box.

joelgeraci
  • 4,606
  • 1
  • 12
  • 19