我正在尝试实现以下结构:
Label: - Value 1
- Value 2
- Value 3
这是我的代码:
document.add(new Chunk("Label: ", BOLD));
List list = new List(List.UNORDERED);
list.add(new ListItem(new Chunk("Value 1")));
list.add(new ListItem(new Chunk("Value 2")));
list.add(new ListItem(new Chunk("Value 3")));
document.add(list);
但它正在生成:
Label:
- Value 1
- Value 2
- Value 3
我该怎么做?
最佳答案
List
功能不支持您想要实现的目标,因此您需要使用 PdfPTable
来解决问题。如果创建了 ListWithLabel显示所需结果的示例:
PdfPTable table = new PdfPTable(2);
table.setTotalWidth(200);
table.setWidths(new int[]{ 1, 10 });
table.setHorizontalAlignment(Element.ALIGN_LEFT);
PdfPCell cell;
cell = new PdfPCell();
cell.setBorder(PdfPCell.NO_BORDER);
cell.addElement(new Paragraph("Label"));
table.addCell(cell);
cell = new PdfPCell();
cell.setBorder(PdfPCell.NO_BORDER);
List list = new List(List.UNORDERED);
list.add(new ListItem(new Chunk("Value 1")));
list.add(new ListItem(new Chunk("Value 2")));
list.add(new ListItem(new Chunk("Value 3")));
cell.addElement(list);
table.addCell(cell);
关于java - 如何将标签设置为 iText 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21579204/