I would like to modify the height of a table row in an existing pdf document. I would like the content below the table to be automatically moved down when the row height is increased. I have tried with hummuspdf, but there doesn't seem to be en explicit way to do this. Is there a way to accomplish my requirement programatically?
-
Which version of iText are you using. Changing the row height is quite trivial in both iText 5 and iText 7, but the code to do this is quite different depending on the version you are using. Show some of your code. Show what you've tried. (Unless you're talking about editing *an existing PDF*. That is *of course* impossible no matter which software you're using.) – Bruno Lowagie Aug 02 '17 at 15:06
-
*"Unless you're talking about editing an existing PDF"* - I have a feeling that that is the case... – mkl Aug 02 '17 at 15:12
-
That's correct. I am trying to edit an exiting pdf. Update my question. Thanks! – Raj Aug 02 '17 at 15:21
1 Answers
I would like to modify the height of a table row in an existing PDF document.
You're not going to like the answer to this: It's technically possible, but a lot harder than you think it is.
There's 2 major roadblocks here: 1) PDF is not designed to be an editable format. 2) A PDF document has no concept of a table.
To expand on 2), a PDF in essence contains a series of drawing and text instructions referencing absolute positions. A table is nothing more than a set of text instructions and line drawing instructions that happen to visually represent a table.
These instructions don't even have to be close to each other in the file. It's entirely possible the line strokes for the borders are found at the top of the file and all but one text instruction near the end of the file, with a final instruction lazing around somewhere in the middle.
Unless structure has been explicitly added during creation (see Tagged PDFs), there's no guarantee you programmatically identify the set of instructions that visually resemble a table to you.
Now, suppose you are in luck and you have managed to do just that, and you now you want to increase table height, and probably have the rest of the contents adapt to the new height. Now 1) comes into play. Because PDF instructions reference absolute coordinates, you have to recalculate everything that would be affected: the lines that make up the borders, text inside the table, all contents below the table etc..
And remember, all contents below the table in the document aren't necessarily below the table instructions in the file.
If you do succeed at all this, I imagine a lot of people would be very interested in your solution.
tl;dr:
There's a reason why this seemingly trivial functionality is not present in commonly used PDF libraries, and that's because the PDF format makes it a hard problem.

- 8,483
- 2
- 23
- 54

- 1,639
- 11
- 15
-
2And don't forget, there might be footer lines which one obviously doesn't want to move down, instead you would want previous lines that would be moved into the footer area to go to the next page. Or to the next column which might be on the same page. Machine readable information about these (and many more) details are not necessarily embedded in the PDF, and implementing routines which recognize such structures is not really trivial either... – mkl Aug 03 '17 at 12:57