java - 如何在 iText 中添加无边框表格

标签 java itext

我想添加两个字符串来对齐同一行的两侧。对于这项任务,我使用一张 table 。我希望这张 table 是无边框的。我尝试了几个例子,但没有任何效果。

这是当前代码:

    public void footer(Document document, String date) throws DocumentException {

    document.add(new Paragraph("footer"));
    Paragraph paragraph = new Paragraph(date);
    paragraph.setAlignment(Element.ALIGN_RIGHT);
    Paragraph paragraph2 = new Paragraph("ABC Holdings (pvt) Ltd");


    PdfPTable table = new PdfPTable(2);
    PdfPCell cellOne = new PdfPCell(new Phrase(paragraph));
    PdfPCell cellTwo = new PdfPCell(new Phrase(paragraph2));
    table.getDefaultCell().setBorder(0);

    table.addCell(cellOne);
    table.addCell(cellTwo);

    document.add(table);

}

最佳答案

好的,我解决了。 iText提供了操作表格的方法。

    public void footer(Document document, String date) throws DocumentException {

    document.add(new Paragraph("footer"));
    Paragraph paragraph = new Paragraph(date);
    paragraph.setAlignment(Element.ALIGN_RIGHT);
    Paragraph paragraph2 = new Paragraph("ABC Holdings (pvt) Ltd");


    PdfPTable table = new PdfPTable(2);
    PdfPCell cellOne = new PdfPCell(new Phrase(paragraph));
    PdfPCell cellTwo = new PdfPCell(new Phrase(paragraph2));

    cellOne.setBorder(Rectangle.NO_BORDER);
    cellTwo.setBorder(Rectangle.NO_BORDER);
    cellOne.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellTwo.setHorizontalAlignment(Element.ALIGN_RIGHT);
    table.setWidthPercentage(100);

    table.addCell(cellOne);
    table.addCell(cellTwo);

    document.add(table);

}

关于java - 如何在 iText 中添加无边框表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48223594/

相关文章:

c# - iTextSharp 中的 Pades LTV 验证抛出公钥不是用于根 CA 证书的证书签名

java - 使用 iText 的 PDF 中的 HTML 表格

java - 从 JPEG 数据到完整的 JPEG 文件

java - 当我使用套接字通过本地网络传输文件时,如何防止文件损坏?

java - 使用 iText 解析 PDF 发布数据时抛出异常

java - 如何处理 API 中以不同格式返回日期时间的 LocalDateTime?

java - 如何在 SQLData.writeSQL() for Oracle 中将 java.sql.Array 写入 java.sql.SQLOutput

java - 使用 iText 5 或 7 将图像层添加到 pdf

java - 如何在文件名中存储带有 @GenerateValue id 的图像?

java - jsp设置变量变量名