Search code examples
itextitextpdf

ItextPdf : get Y position


I'm using itextpdf 5 in my project

I want to draw a change bar for any element.

My method drawBar take in input Y1 and Y2 positions like this :

drawBar(float y1, float y2, PdfWriter writer){
// draw bar
}

But I dont know how to get Y position for current pointer. Is it feasible ?


Solution

  • You are looking for the getVerticalPosition() method on the PdfWriter. To get the "current" Y pass false to this and to get the "next" Y as if a line break were added pass true.