0

How to use i text 5 to get the length and width of the content in the PDF document? In another word,

enter image description here

gets the length and width of the red rectangle in the image

mkl
  • 90,588
  • 15
  • 125
  • 265
Crist_Wu
  • 1
  • 1
  • So you have an existing PDF and want the bounding rectangle of its text content on a given page? – mkl Jun 29 '17 at 14:35
  • You might want to look at the iText example [ShowTextMargins](http://developers.itextpdf.com/examples/itext-action-second-edition/chapter-15#579-showtextmargins.java). – mkl Jun 29 '17 at 14:42

1 Answers1

0

This answer to this question can be found on the FAQ section of the iText website.

http://developers.itextpdf.com/question/how-find-out-current-cursor-position-page

One way is to use document.add()

[source itextpdf.com]

There is a very old method called getVerticalPosition() that takes a boolean as parameter. I'm not proud of that method as it is a getter method that not only will give you the Y position on the page after using a series of document.add() operations, it can also change the current Y position (and that is not what a getter method should do).

If you pass false as a parameter, it will give you the current Y, which could be the position of the baseline of the last Chunk you've added.

If you pass true as a parameter, the method will first add a newline and give you the position of the baseline of the "next" line of text you'll be adding.

Joris Schellekens
  • 8,483
  • 2
  • 23
  • 54