我想以行和列显示记录集。正在获取输出,但事实是,它正在重叠。我应该修改循环吗,有人可以建议。
ArrayList<ResultRecord> Records = new ArrayList<ResultRecord>(MainRestClient.fetchResultRecords(this.savedMainLog));
for(j=0; j<Records.size(); j++)
{
Row<PDPage> row4 = table.createRow(100.0f);
Cell<PDPage> cell10 = row4.createCell(15.0f, temp.getNumber());
Cell<PDPage> cell11 = row4.createCell(45.0f, temp.getDescription());
Cell<PDPage> cell12 = row4.createCell(15.0f, temp.getStatus());
Cell<PDPage> cell13 = row4.createCell(25.0f, temp.getRemarks());
}
下面是打开PDF文件的完整代码。我想检索相应单元格中row4中的记录集。但是,一个被覆盖在另一个之上。预期产量:IT应该在另一个下方显示。是重叠的原因,是因为将行定义为row4。
System.out.println("----------------------Report starts-------------------------------------------");
System.out.println(MainRestClient.fetchResultRecords(this.savedMainLog));
ArrayList<ResultRecord> Records = new ArrayList<ResultRecord>(MainRestClient.fetchResultRecords(this.savedMainLog));
System.out.println(Records.size());
//Creating PDF document object
PDDocument document = new PDDocument();
PDPage page = new PDPage(PDRectangle.A4);
// PDRectangle.LETTER and others are also possible
PDRectangle rect = page.getMediaBox();
document.addPage(page);
boolean drawContent = true;
float margin = 50;
// starting y position is whole page height subtracted by top and bottom margin
float yStartNewPage = page.getMediaBox().getHeight() - (2 * margin);
// we want table across whole page width (subtracted by left and right margin ofcourse)
float tableWidth = page.getMediaBox().getWidth() - (2 * margin);
float bottomMargin = 70;
// y position is your coordinate of top left corner of the table
float yPosition = 550;
System.out.println("PDF created");
for(int i=0;i<Records.size();i++) {
System.out.println(Records.get(i));
ResultRecord temp = (ResultRecord) Records.get(i);
BaseTable table = new BaseTable(yPosition, yStartNewPage,
bottomMargin, tableWidth, margin, document, page, true, drawContent);
Row<PDPage> row = table.createRow(20.0f);
Cell<PDPage> cell = row.createCell(50.0f, "Checklist Number:" + temp.getChecklistId());
Cell<PDPage> cell1 = row.createCell(50.0f, "CDSID:" + temp.getCDSID());
Row<PDPage> row1 = table.createRow(20.0f);
Cell<PDPage> cell2 = row1.createCell(50.0f, "Program Name:" + temp.getProgramName());
Cell<PDPage> cell3 = row1.createCell(50.0f, "Study Name:" + temp.getStudyName());
Row<PDPage> row2 = table.createRow(20.0f);
Cell<PDPage> cell4 = row2.createCell(50.0f, "Part Name:" + temp.getPartName());
Cell<PDPage> cell5 = row2.createCell(50.0f, "Study Date:" + temp.getStudyDate());
Row<PDPage> row3 = table.createRow(20.0f);
Cell<PDPage> cell6 = row3.createCell(15.0f, "Issue Number");
Cell<PDPage> cell7 = row3.createCell(45.0f, "Issue Description:");
Cell<PDPage> cell8 = row3.createCell(15.0f, "Issue status:");
Cell<PDPage> cell9 = row3.createCell(25.0f, "Remarks:");
for(int j=0; j<Records.size(); j++)
{
Row<PDPage> row4 = table.createRow(100.0f);
Cell<PDPage> cell10 = row4.createCell(15.0f, temp.getNumber());
Cell<PDPage> cell11 = row4.createCell(45.0f, temp.getDescription());
Cell<PDPage> cell12 = row4.createCell(15.0f, temp.getStatus());
Cell<PDPage> cell13 = row4.createCell(25.0f, temp.getRemarks());
}
try {
table.draw();
cell.setFontSize(12);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
try {
document.save("C:\\my_doc.pdf");
document.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}`
首先,您应该弄清所使用的表格图形库。 PDFBox仅是基础PDF库。考虑使用的类,我假设您在其顶部使用Boxable。
此外,所有表格彼此打印的原因是,您使用同一页上相同位置的每个表格来启动]
BaseTable table = new BaseTable(yPosition, yStartNewPage,
bottomMargin, tableWidth, margin, document, page, true, drawContent);