首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在PDFTables中显示两个iText相邻的

如何在PDFTables中显示两个iText相邻的
EN

Stack Overflow用户
提问于 2015-07-27 13:18:55
回答 2查看 3.5K关注 0票数 1

我需要你的帮助,把两个PDFTables放在iText里。现在,第一张桌子在第二张桌子上,现在我需要用一个很短的空间把它们放在一起。这是我的代码:

代码语言:javascript
复制
//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);
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-27 13:40:21

(并排桌)我不确定只是检查一下。

代码语言:javascript
复制
    // 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);
票数 3
EN

Stack Overflow用户

发布于 2015-07-27 13:41:40

使用

代码语言:javascript
复制
doc.add(new Phrase("\n"));

代替

代码语言:javascript
复制
doc.add(Chunk.NEWLINE);

显然这是你的工作。:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31654191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档