gpt4 book ai didi

java - 如何在 iText 中相邻显示两个 PDFTable

转载 作者:行者123 更新时间:2023-11-30 03:19:38 25 4
gpt4 key购买 nike

我需要您的帮助来在 iText 中显示两个相邻的 PDFTable。现在第一个 table 位于第二个 table 上方,现在我需要将它们彼此相邻并留出一小段空间。这是我的代码:

//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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com