在iText中彼此相邻显示两个PDFTables时,我需要您的帮助。现在,第一个表位于第二个表的上方,现在我需要在它们之间保持较短的间距。这是我的代码:
//First Table
dfPTable table = new PdfPTable(2);
Font earningsTitlefont = new Font(Font.TIMES_ROMAN,12, Font.BOLD);
PdfPCell c1 = new PdfPCell(new Phrase("Earnings Description",earningsTitlefont));
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Earnings Amount",earningsTitlefont));
table.addCell(c1);
for (int i = 0; i < listEarnings.size(); i++) {
String temp1 = listEarnings.get(i).getEarningsDescriptionSS();
String temp2 = listEarnings.get(i).getEarningsAmountSS();
table.addCell(temp1);
table.addCell(temp2);
}
//Second Table
dfPTable tableDeductions = new PdfPTable(2);
Font fontTitleDeductions = new Font(Font.TIMES_ROMAN,12, Font.BOLD);
PdfPCell c2= new PdfPCell(new Phrase("Deductions Description",fontTitleDeductions ));
tableDeductions.addCell(c2);
c2 = new PdfPCell(new Phrase("Deductions Amount",fontTitleDeductions));
tableDeductions.addCell(c2);
for (int i = 0; i < listDeductionss.size(); i++) {
String temp3 = listDeductions.get(i).getDeductionssDescriptionSS();
String temp4 = listDeductions.get(i).getDeductionssAmountSS();
tableDeductions.addCell(temp3);
tableDeductions.addCell(temp4);
}
doc.add(table);
doc.add(Chunk.NEWLINE);
doc.add(tableDeductions);
最佳答案
(并排表)我不确定只是检查一下。
// Main table
PdfPTable mainTable = new PdfPTable(2);
mainTable.setWidthPercentage(100.0f);
// First table
PdfPCell firstTableCell = new PdfPCell();
firstTableCell.setBorder(PdfPCell.NO_BORDER);
PdfPTable firstTable = new PdfPTable(2);
//......... add some cells here ...........
firstTableCell.addElement(firstTable);
mainTable.addCell(firstTableCell);
// Second table
PdfPCell secondTableCell = new PdfPCell();
secondTableCell.setBorder(PdfPCell.NO_BORDER);
PdfPTable secondTable = new PdfPTable(2);
//......... add some cells here ...........
secondTableCell.addElement(secondTable);
mainTable.addCell(secondTableCell);
paragraph.add(mainTable);
document.add(paragraph);
关于java - 如何在iText中彼此相邻显示两个PDFTable,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31654191/