OpenPDF
OpenPDF copied to clipboard
Blank page if second PTable is not fit on 1 page.
I created 2 PTable, both table should be in separated page. Step 1. document.add(table1) -> fits on page Step 2. document.newPage() Step 3. document.add(table2) -> this is not fit on 1 page, It's dynamic table. The blank page is occurs on page 2. Page 1 -> table 1 (fits) Page 2 -> blank Page 3 -> table 2 Page 4 -> table 2 (continued).
The method addPTable, in looping create a newPage in the first loop.
while (true) {
ct.setSimpleColumn(indentLeft(), indentBottom(), indentRight(), indentTop() - currentHeight);
int status = ct.go();
if ((status & ColumnText.NO_MORE_TEXT) != 0) {
text.moveText(0, ct.getYLine() - indentTop() + currentHeight);
currentHeight = indentTop() - ct.getYLine();
break;
}
if (indentTop() - currentHeight == ct.getYLine())
++loop;
else
loop = 0;
if (loop == 3) {
add(new Paragraph("ERROR: Infinite table loop"));
break;
}
newPage();
}
This probably correct if i didn't call newPage(), but if i didn't call a newPage() and table 2 fits on 1 page, Both table is not in separated page. Please give me a suggestion. Should this code changed when the first time loop won't create a new page ?
You code is hard to understand, because there are missing some information about the variables and methods you are using and how you build your table (for example. what is newPage() doing?). That's why I can't reproduce your problem.
I've made a short example and with this it worked. The first table is on the first page. Then the second table is on the second page and continues on the third page.
Maybe this helps you.
public class Start {
public static final String LOREM_IPSUM = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. \n"
+ "\n"
+ "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. \n"
+ "\n"
+ "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. \n"
+ "\n"
+ "Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. \n"
+ "\n"
+ "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis. \n"
+ "\n"
+ "Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo";
public static void main(final String[] args) throws DocumentException, FileNotFoundException {
final Document doc = new Document();
final PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("<your_export_path>"));
doc.open();
tableBlankPage(doc);
doc.close();
}
private static void tableBlankPage(Document doc) {
final PdfPTable table = new PdfPTable(1);
PdfPCell cell = new PdfPCell(new Paragraph(LOREM_IPSUM));
table.addCell(cell);
doc.add(table);
doc.newPage();
final PdfPTable table2 = new PdfPTable(1);
table2.addCell(LOREM_IPSUM + LOREM_IPSUM + LOREM_IPSUM + LOREM_IPSUM);
doc.add(table2);
}
}
Agree with @razilein, his provided code works and couldn't see any blank page [Verified on openPdf-1.3.29]
Agree with @razilein, his provided code works and couldn't see any blank page [Verified on openPdf-1.3.29]
I'm a girl 😉 but thanks for your approval.
Seams to be an usage issue. Closing now