The following code will kill the JVM when executed in a 64-bit JVM (tested in 1.8_111 - some earlier JVMs are OK)
package com.test.pdf.table;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Random;
import com.cete.dynamicpdf.Document;
import com.cete.dynamicpdf.Font;
import com.cete.dynamicpdf.Page;
import com.cete.dynamicpdf.PageSize;
import com.cete.dynamicpdf.RgbColor;
import com.cete.dynamicpdf.TextAlign;
import com.cete.dynamicpdf.pageelements.Label;
import com.cete.dynamicpdf.pageelements.Row2;
import com.cete.dynamicpdf.pageelements.Table2;
public class TableCreator {
private int rowCount = 0;
private int colCount = 0;
private Random RAND = new Random(System.currentTimeMillis());
private String rowCellData = "X";
public static File pdfDir = new File(System.getProperty("user.dir") + File.separator + "pdfs");
public TableCreator( final int rows, final int cols) {
this.rowCount = rows;
this.colCount = cols;
}
public void run()
{
System.out.println("Printing table: ROWS = " + rowCount + ", COLS = " + colCount);
String fileName = "out-" + rowCount + "-" + colCount + ".pdf";
File out = new File(System.getProperty("user.dir") + File.separator + "pdfs", fileName);
System.out.println("Will create file at: " + out.getAbsolutePath());
FileOutputStream fos = null;
try {
// Create a document and set it's properties
Document document = new Document();
Table2 table = new Table2(0, 0, 512, 676, Font.getHelvetica(), 12);
buildTable(table);
addPage(document, table, "(1, 1)");
addPage(document, table.getOverflowColumns(), "(1, 2)");
Table2 overflowRowTable = table.getOverflowRows();
if (overflowRowTable != null) {
addPage(document, overflowRowTable, "(2, 1)");
Table2 overflowColumns = overflowRowTable.getOverflowColumns();
if (overflowColumns != null) {
addPage(document, overflowColumns, "(2, 2)");
}
}
fos = new FileOutputStream(out);
document.draw(fos);
} catch (Throwable t) {
t.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
}
}
private void addPage(Document document, Table2 table, String pageLabel) {
Page page = new Page(PageSize.LETTER);
if (table != null) {
page.getElements().add(table);
}
page.getElements().add(new Label(pageLabel, 0, page.getDimensions().getBody().getHeight() - 12,
page.getDimensions().getBody().getWidth(), 12, Font.getHelvetica(), 12, TextAlign.CENTER));
document.getPages().add(page);
}
private void buildTable(Table2 table) {
// add columns to table
for( int idx=0; idx<this.colCount; idx++) {
table.getColumns().add(50);
}
// add data rows to table
for (int row = 0; row<rowCount; row++) {
final boolean flag = RAND.nextBoolean();
// FIXME: This is where the JVM crashes - change to false to not fail
addRow(table, flag, true);
//
}
}
private float addRow(final Table2 currentTable, final boolean flag, final boolean fail) {
Row2 row = null;
if( flag ) {
row = currentTable.getRows().add(20, Font.getHelveticaBold(), 10, RgbColor.getBlue(), RgbColor.getLightGrey());
for (int col=0; col<colCount; col++) {
if( !fail ) {
row.getCells().add(rowCellData, Font.getHelveticaBold(), 10, RgbColor.getBlue(), RgbColor.getLightGrey(), 1);
} else {
row.getCells().add(rowCellData);
}
}
} else {
row = currentTable.getRows().add();
for (int col=0; col<colCount; col++) {
if (col == 0) {
row.getCells().add(rowCellData, Font.getHelveticaBold(), 6, RgbColor.getBlack(), RgbColor.getWhite(), 1);
} else {
row.getCells().add(rowCellData, Font.getHelvetica(), 6, RgbColor.getBlack(), RgbColor.getWhite(), 4);
}
}
}
return row == null ? 0f : row.getActualRowHeight();
}
}