Can't create file and download pdf when creating a pdf with table

Hello all,

I am using Aspose 20.11 to create pdf with table.
Table is one row. height of row is height of page.
Download button click then not response.

main.java

Page page = this.pdfDocument.getPages().add();
MarginInfo pageMarginInfo = new MarginInfo(this.pageMarginLeft, this.pageMarginBottom,
this.pageMarginRight, this.pageMarginTop);
page.getPageInfo().setMargin(pageMarginInfo);
// A4横
page.setPageSize(this.pageWidth * MM_TO_PT, this.pageHeight * MM_TO_PT);
TextFragment textFTitle = this.createTitle();
TextFragment textFPage = this.createPageItem();
TextFragment textFOutputDateTime = this.createOutputDateTime();
double pagerTop = -textFOutputDateTime.getTextState().getTextHeight()
- textFPage.getTextState().getTextHeight() - 3;
double outputDateTimeTop = -textFOutputDateTime.getTextState().getTextHeight() + 3;
textFPage.setMargin(new MarginInfo(0, 0, 0, pagerTop));
textFOutputDateTime.setMargin(new MarginInfo(0, 0, 0, outputDateTimeTop));
Table tableDetail = this.createDetail();
double tableDetailTop = page.getPageInfo().getMargin().getTop()
+ textFTitle.getTextState().getTextHeight() + this.tableMarginTop - this.pageMarginTop;
MarginInfo tableMarginInfo = new MarginInfo(0, 0, 0, tableDetailTop);
tableDetail.setMargin(tableMarginInfo);
page.getParagraphs().add(tableDetail);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
this.pdfDocument.save(baos);
try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) {
this.pdfDocument = new Document(bais);
}
}
PageCollection pageCollection = this.pdfDocument.getPages();
for (int index = 1; index <= pageCollection.size(); index++) {
page = pageCollection.get_Item(index);
page.getPageInfo().setMargin(pageMarginInfo);
page.getParagraphs().add(textFTitle);
page.getParagraphs().add(textFOutputDateTime);
page.getParagraphs().add((TextFragment) textFPage.deepClone());
}
this.setPdfDocInfo(textFTitle.getText());

function table

private Table createDefault() {
Table table = new Table();
table.setDefaultCellBorder(new BorderInfo((int) BorderSide.All, BORDER_WIDTH_DEFAULT_CELL));
table.setBorder(new BorderInfo((int) BorderSide.All, BORDER_WIDTH_DEFAULT_OUTLINE));
TextState tss = new TextState(this.font.getFontName(), this.fontSizeData);
table.setDefaultCellTextState(tss);
MarginInfo margin = new MarginInfo(this.cellMarginLeft, this.cellMarginBottom,
this.cellMarginRight, this.cellMarginTop);
table.setDefaultCellPadding(margin);
return table;
}
private Table createDetail() {
Table tableDetail = this.createDefault();
tableDetail.setRepeatingRowsCount(1);
tableDetail.setMargin(new MarginInfo(this.tableMarginLeft, this.tableMarginBottom,
this.tableMarginRight, this.tableMarginTop));
tableDetail.setColumnWidths(this.tableWidths);
Row row = tableDetail.getRows().add();
row.setBackgroundColor(COLOR_DEFAULT_ITEM_NAME);
row.getCells().add(“Log”);
int dataCount = this.LogList.size();
for (int i = 0; i < dataCount; i++) {
Log data = this.LogList.get(i);
row = tableDetail.getRows().add();
row.setVerticalAlignment(VerticalAlignment.Top);
row.getCells().add(data.getLogDetail());
}
return tableDetail;
}

Thanks

@khietnt

Could you please share the sample code snippet that you are using at your end for this whole process. We will test the scenario in our environment and address it accordingly.

thanks you.
sample code added.

@khietnt

We tried to test the scenario using the code snippet that you have shared. We could not run it as there were many undefined variables and objects in it. Could you please share a narrowed down code snippet which can be run without any error and issue can be replicated on our side. We will again test the scenario in our environment and address it accordingly.

@asad.ali thanks you response.

just edited. please check it. thanks you

Page page = this.pdfDocument.getPages().add();
MarginInfo pageMarginInfo = new MarginInfo(3,3,3,3);
page.getPageInfo().setMargin(pageMarginInfo);
page.setPageSize(297, 210);
TextFragment textFTitle = new TextFragment(“Title”);
Table tableDetail = new Table();
tableDetail.setRepeatingRowsCount(1);
tableDetail.setMargin(new MarginInfo(0,0,0,5));
tableDetail.setColumnWidths(791);
Row row = tableDetail.getRows().add();
row.getCells().add(“Log”);
row = tableDetail.getRows().add();
row.setVerticalAlignment(VerticalAlignment.Top);
row.getCells().add(“data of heigth is page of heigth”);
double tableDetailTop = page.getPageInfo().getMargin().getTop()+ textFTitle.getTextState().getTextHeight() + 25;
MarginInfo tableMarginInfo = new MarginInfo(0, 0, 0, 10);
tableDetail.setMargin(tableMarginInfo);
page.getParagraphs().add(tableDetail);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
this.pdfDocument.save(baos);
try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) {
this.pdfDocument = new Document(bais);
}
}
PageCollection pageCollection = this.pdfDocument.getPages();
for (int index = 1; index <= pageCollection.size(); index++) {
page = pageCollection.get_Item(index);
page.getPageInfo().setMargin(pageMarginInfo);
page.getParagraphs().add(textFTitle);
}
this.setPdfDocInfo(textFTitle.getText());

ISSUE : row.getCells().add(“data of heigth is page of heigth”);
Case table has 1 row. The height of that line is equal to one page. The problem happened.

@khietnt

We have used the same code snippet that you have shared and did not notice any issue. The PDF file was generated correctly at our end. We used 21.2v of the API for testing purposes as it is always recommended to use the latest version.

For your kind reference, an output PDF is also attached. Please try to use the latest version of the API at your side and let us know if issue still persists.

output.pdf (2.3 KB)

@asad.ali thanks you response.

I’m sorry, about my english.
[data of heigth is page of heigth] is full page pdf then problem happened.
Please check it.

image :
Screenshot by Lightshot

best regards
KNT.

@khietnt

We tested the scenario again by adding more text to the row so that its height was equal to the page boundary. We did not face any issue. An output PDF is also attached for your kind reference, please check it and share a sample console application which is able to reproduce the issue that you are facing. We will further proceed to assist you accordingly.output.pdf (2.3 KB)

1 Like

@asad.ali thanks you.
I will check it.