OpenPDF icon indicating copy to clipboard operation
OpenPDF copied to clipboard

In PDF we can see additional top space in a cell containing text

Open bk1991 opened this issue 2 years ago • 2 comments

Describe the bug In PDF we can see additional top space/padding for table cell containing text, but there is no space at bottom of cell and hence text gets overlap on cell bottom border for characters like y.p.q which gets extended below the baseline.

To Reproduce Code to reproduce the issue public class TopGap { public static final String LOREM_IPSUM = "The quick brown fox jumps over the lazy dog.";

public static void main(final String[] args) throws DocumentException, FileNotFoundException {
    final Document doc = new Document();
    final PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("D:\\output.pdf"));
    doc.open();
    addTable(doc);
    doc.close();
}
private static void addTable(Document doc) {
    final PdfPTable table = new PdfPTable(1);
    PdfPCell cell = new PdfPCell(new Paragraph(LOREM_IPSUM));
    cell.setPaddingTop(0.0f);
    table.addCell(cell);
    table.addCell(cell);
    doc.add(table);
}

}

Expected behavior The text should be rendered in a cell such that leaving equal space/default padding both from top and bottom

Screenshots image

System (please complete the following information):

  • OS: Windws10
  • Used Font: Default (Helvetica)

bk1991 avatar Oct 20 '22 15:10 bk1991

This is actually the behavior of iText 2.1.7. Changing this will make PDF-Rendering of a lot of OpenPDF users break.

Thus adding a new API for adding that padding in the bottom would be ok, if not already there.

asturio avatar May 27 '24 18:05 asturio

Pull Requests are welcome.

asturio avatar May 27 '24 18:05 asturio