OpenPDF
OpenPDF copied to clipboard
setVerticalAlignment methods for Cell class causes endless loop when starting a new page
Describe the bug
the same as #514 but adding codes to reproduce it
- Create a
Table
instance which has at least 2 columns in document - Add a
Cell
into the first column which should callsetVerticalAlignment
method, and the second column should have a cell with a large String which will make the document start a new page - Run code. The program cannot stop in short time and size of the output pdf will become will large
To Reproduce
public void test() throws FileNotFoundException {
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
Table table = new Table(2);
Cell cell = new Cell("any text");
cell.setVerticalAlignment(VerticalAlignment.BOTTOM);
table.addCell(cell);
StringBuilder largeStr = new StringBuilder();
for (int i = 0; i < 45; i++) {
largeStr.append(String.format("this is to test-> row %d\n", i));
}
table.addCell(new Phrase(largeStr.toString()) );
document.open();
document.add(table);
document.close();
}
Expected behavior size of output pdf should be small and it can be generated very fast
Bug Screenshots
Additional context
You can make i
in the for
loop smaller so there won't a new page and no bug will happen.
I will try to fix it.