Skip to content

Rowspan not working properly in OpenPDF 3.0 #1529

@cyChop

Description

@cyChop

Describe the bug

Rowspan isn't applied properly, though I observe different behaviors and cannot explain them.

To Reproduce

import java.io.File;
import java.io.FileOutputStream;
import org.openpdf.text.Chunk;
import org.openpdf.text.Document;
import org.openpdf.text.PageSize;
import org.openpdf.text.pdf.PdfPCell;
import org.openpdf.text.pdf.PdfPTable;
import org.openpdf.text.pdf.PdfStream;
import org.openpdf.text.pdf.PdfWriter;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    static void main() throws Exception {
        Document document = new Document(PageSize.A4, 10, 10, 10, 10);
        File file = new File("test.pdf");
        FileOutputStream fos = new FileOutputStream(file);
        PdfWriter writer = PdfWriter.getInstance(document, fos);

        writer.open();
        writer.setFullCompression();
        writer.setCompressionLevel(PdfStream.BEST_COMPRESSION);
        document.open();

        float width = document.getPageSize().getWidth() - 20;

        float[] columns = {50f, 50f};
        PdfPTable table = new PdfPTable(columns);
        table.setTotalWidth(width);
        table.setLockedWidth(true);
        table.setHeaderRows(1);

        PdfPCell cell = new PdfPCell();
        cell.setRowspan(2);
        cell.addElement(new Chunk("rowspanrowspanrowspanrowspanrowspanrowspanrowspanrowspanrowspanrowspanrowspanrowspanrowspanrowspanrowspan"));
        table.addCell(cell);

        table.addCell("row1");
        table.addCell("row2");
        document.add(table);

        document.close();
        writer.close();
        fos.close();
    }
}

Expected behavior

The left column should be one single cell spanning two rows.

Screenshots

From the sample code:

Image

If the Chunk's content is reduced to a single "rowspan":

Image

Interestingly enough, from my (unstable) non-sample code (migration from iText 9 in progress). The empty sections should be filled by the rowspan=5 cells. This also goes to prove there's no issue with colspan.

Image

System

  • OS: Win 10, WSL2
  • Used font:
  • OpenPDF version: 3.0.3

Your real name

Asking me this on a public form isn't really good form, and I don't understand the purpose of proving my identity. I am not a chatbot and my account's history should prove it, if that's the concern. Anyway, click my name, it'll show up on my profile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions