我想添加两个字符串来对齐同一行的两边。对于这个任务我正在使用一个表。我希望这张桌子不含边框。我尝试了一些例子,但没有任何效果。
这是当前的代码:
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);
}
答案 0 :(得分:2)
好的,我解决了。 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);
}