Reputation: 153
I'm creating document in iText. I need custom width however when it's smaller than A4 standard width, it should be set to A4 standard width.
So I got:
float pageWidth = columns.size() * 100;
if (pageWidth < PageSize.A4.getWidth()) {
pageWidth = PageSize.A4.getWidth();
}
table.setTotalWidth(pageWidth);
And it's not working, probably because pageWidth
and PageSize.A4.getWidth()
got different units.
When I debugged this, I got 900.0
value in pageWidth
and PageSize.A4.getWidth()
returns 595.0
So what do I need to change to get same units for comparison?
Upvotes: 1
Views: 5196
Reputation: 77528
900 is not lower than 595, so pageWidth<PageSize.A4.getWidth()
is not true, and this is never executed: pageWidth = PageSize.A4.getWidth();
The value of pageWidth
never changes. You have 9 colums. You multiply with 100 and that results in 900. 900 is bigger than 595, so pageWidth
remains 900.
I think you want the opposite of what you're asking:
float pageWidth = columns.size()*100;
if(pageWidth > PageSize.A4.getWidth()){
pageWidth = PageSize.A4.getWidth();
}
table.setTotalWidth(pageWidth);
Now, when pageWidth
doesn't fit he page, it will be reduced to 595.
I think you made a logical error that is totally unrelated to iText.
Upvotes: 3