PDFcells not displaying correctly, few cells are moving to next page in PdfWriter in Java

40 Views Asked by At

I am trying to create the PDF using the PdfWriter.

Document document = new Document(PageSize.A4);

PdfWriter.getInstance(document, new FileOutputStream("some file path"));
document.open();

Font font1 = FontFactory.getFont(FontFactory.HELVETICA_BOLD);
font1.setSize(10);
font1.setColor(Color.BLUE);

PdfPTable table = new PdfPTable(8);
table.setWidthPercentage(100f);
table.setWidths(new int[] { 1, 1, 1, 1, 1, 1, 1, 3 });
table.setSpacingBefore(10);
table.setHorizontalAlignment(Element.ALIGN_CENTER);

PdfPCell cell1 = new PdfPCell();
//cell1.setBorder(Rectangle.NO_BORDER);
cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
cell1.setBackgroundColor(Color.DARK_GRAY);
cell1.setPadding(5);
font1.setColor(Color.WHITE);    
cell1.setPhrase();

table.addCell(cell1);

My PDF looks like this : enter image description here

Why the cells are all distorted is what i dont understand

1

There are 1 best solutions below

0
Swathi On
tablename.setSplitLate(false);

is the one fixed the issue.

    /**
     * If true the row will only split if it's the first one in an empty page.
     * It's true by default.
     * It's only meaningful if setSplitRows(true).
     * 
     * @param splitLate the property value
     */
    public void setSplitLate(boolean splitLate) {
        this.splitLate = splitLate;
    }