When creating a pdf with itextpdf -PdfPTable while adding table in any of a row it's displaying a dark border at bottom

306 views Asked by At

enter image description here While creating a table through itextpdf getting a dark border in a certain cell. But I have not specified any border had set only border color to gray. Getting this only while viewing the PDF in Adobe Reader in 100% zoom. if zoom size is increased or decreased its border looks the same among all cell.

Darker only when viewing the PDF with 100% zooming ratio.

PdfPTable contentTable = new PdfPTable(new float[] {3, 1, 1, 1, 1, 1, 1, 1});
contentTable.setWidthPercentage(100);
PdfPCell cell;
cell = new PdfPCell(new Phrase(columnName, valueFont));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setBorderColor(BaseColor.GRAY);
cell.setUseDescender(true);
cell.setPaddingLeft(5f);
contentTable.addCell(cell); 
document.add(contentTable);
1

There are 1 answers

0
mkl On

Please be aware that PDF doesn't know about resolutions and that it positions stuff like lines exactly at given coordinates, usually given in pt (point) which is 1/72in (using real world inches).

In a PDF viewer at a given zoom level such coordinates may be clearly inside a screen pixel or they may be on or near the border of two adjacent pixels. In the former case a thin line may have a width of a single pixel while in the latter case it must be two pixels wide to not appear located at the wrong position, half a pixel off.

Coordinates on the border of pixels are seldom, so these wider lines are seldom and disappear at changed zoom levels.

Thus, those thicker line appearances merely are artifacts of low resolution mediums.


You usually don't get such artifacts for HTML pages in HTML viewers because many HTML pages use px (pixel) as unit for fixed coordinates, and in case of low resolution mediums (like screens) HTML viewers are expected to align the unit px to an integer multiple of actual screen pixels. Meanwhile even other units like in (inch) used in some HTML pages also are expected to be aligned to physical pixels in low resolution mediums, not to the real world unit.