سؤال

i am using iText 5.1.0 for creating the PDF in java . I have 3 blocks of tables , whose sizes may change dynamically

Table 1

.

.

. 

Table 2 

.

.

.

.

End of page 

Now i am in need of the method that would compute the space below the table 2 . And i am using the pagesize as A4

Intially it printed like this ,

But when the data in the previous tables increased it printed , like the 2 nd one. So i would like to calculate the space below if possible before i insert the table

Any suggestions are highly appreciated.

Thank you

هل كانت مفيدة؟

المحلول

There's a method in PdfWriter called getVerticalPosition(). It takes a Boolean parameter that tells iText to ensure a new line or not. If you don't ensure a new line (false), you get the current Y, but that may not be the position you need. If you ensure a new line (true), a new line is added and you get the position where the new line starts.

As you are creating A4 pages from start, and as the Y axis points upwards, you need to subtract the bottom margin from this vertical position to find out how much space is left for your new table.

Note that we aren't happy with the getVerticalPosition() method at iText: having a getter that changes the content of the document isn't very elegant. In cases like yours, we prefer working with ColumnText to take charge over the layout process intstead of letting iText decide where to split a table.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top