【问题标题】:How to reshape table in iTEXT [closed]如何在 iTEXT 中重塑表格 [关闭]
【发布时间】:2018-03-14 09:11:05
【问题描述】:

我正在使用 iTEXT 和 java 创建一个简单的 PDF,其中包含特定形式的表格。 我在 PDF 文件中的表格形状应该是这样的

编辑: 我尝试在代码中使用行跨度

         cell1.setRowspan(2);
         cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
         cell1.setPaddingTop(-13);
         cell1.setPaddingBottom(10);
         PdfPCell cell2 = new PdfPCell(new Phrase("Cell 2"));
         cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
         cell2.setPaddingTop(-13);
         cell2.setPaddingBottom(10);
         PdfPCell cell3 = new PdfPCell(new Phrase("Cell 2"));
         cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
         cell3.setPaddingTop(-13);
         cell3.setPaddingBottom(10);
         //cell.setBorder(Rectangle.NO_BORDER);
         Paragraph p= new Paragraph("توفة توفايات",arabic);
         Paragraph p2= new Paragraph("سناء علاء حسين",arabic);
         Paragraph p3= new Paragraph("سناء سءء~ حسين",arabic);
         p.setAlignment(PdfPCell.ALIGN_LEFT);
         p2.setAlignment(PdfPCell.ALIGN_LEFT);
         cell1.addElement(p);
         cell2.addElement(p2);
         table.addCell(cell1);
         table.addCell(cell2);
         table.completeRow();

事实上,我不知道我是否以正确的方式处理行跨度,因为我的 PDF 仅显示 pp2p3 在 PDF 中没有。

我该怎么做?

【问题讨论】:

  • 你应该分享你已经尝试过的东西。 StackOverflow 旨在帮助彼此解决问题。而不是外包开发。

标签: java itext tabular


【解决方案1】:

是的,您可以使用 iText7 来做到这一点

File outputFile = new File("output.pdf");

PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outputFile));
Document layoutDocument = new Document(pdfDocument);

// table magic
Table table = new Table(new float[]{20f, 20f});
table.addCell(new Cell(1,2).add(new Paragraph("Lorem")));
table.addCell(new Cell().add(new Paragraph("Ipsum")));
table.addCell(new Cell().add(new Paragraph("Dolor")));
layoutDocument.add(table);

// close
pdfDocument.close();        

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-05
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    • 1970-01-01
    相关资源
    最近更新 更多