Points -> pixels iText (im)precision
Okay, here's some code (pdfDocument is a com.itextpdf.text.Document):
PdfPTable table = new PdfPTable(1);
PdfPCell cell = new PdfPCell();
cell.setFixedHeight(3f);
for (int i = 1; i < 100; i++)
{
table.addCell(cell);
}
pdfDocument.add(table);
According to my calculations (pixels = points / 0.75f) 3f points should be
EXACTLY 4 pixels on a screen with 96dpi (which mine is). However, when I
create a table with the code above, I get alternating heights of the cells
4 - 3 - 4 - 3 - 4 - 3 etc...
Why does this happen? I would understand the value I put in was something
that scales to x.6 pixels so every so often would appear one cell that is
a pixel higher than the rest.
eg.:
If I decrease the value to 2f, most of the cells will be 2 pixels high,
but every 10th ot 15th will be 3 pixels high.
If I increase the value to 4f, all cells will be 5 pixels high, but every
third border wll be one pixel thicker.
Also, if I do use x.6 as a value, will the value be rounded (5.99 -> 6) or
floored (5.99 -> 5) to an integer?
Since iText only works with points, I'm guessing it's an internal PDF
thing,. but I'd still like to know.
I need to now exactly how high a cell would be given the float value so I
can precisely predict how high the whole table or object would be so I can
then calucalte that into the composition of the whole page. If I don't
know reliably, it's impossible for me to do.
Is there a reliable way in which I can calculate exactly what the float
value should be for the pdf version to be exactly x pixels high? It seems
that the formula I'm using doesn't work, or maybe there's something else?
No comments:
Post a Comment