我在我的java应用程序中使用iText生成pdf。目标是生成段落,每行在左侧有一些名称,在右侧有值。名称和值之间的空格用点填充:
param1..............value1
param2..............val1, val2
param3..............any text
我正在使用TabStop,一切正常。有我的代码。
/**
* Method that generate paragraph with given indent
* @param firstTabPosition parameter name indent
* @param secondTabPosition value indent
* @param itemNames list of names
* @param itemValues list of values
*/
public Paragraph GetTextListParagraph(int firstTabPosition, int secondTabPosition, ArrayList<String> itemNames, ArrayList<String> itemValues) throws DocumentException {
ArrayList<TabStop> tabList = new ArrayList<>();
tabList.add(new TabStop(firstTabPosition, new VerticalPositionMark()));
tabList.add(new TabStop(secondTabPosition, new DottedLineSeparator()));
Paragraph paragraph = new Paragraph();
paragraph.setTabSettings(new TabSettings(tabList));
for (int index = 0; index < itemNames.size(); index++) {
paragraph.add(Chunk.TABBING);
paragraph.add(itemNames.get(index));
paragraph.add(Chunk.TABBING);
paragraph.add(itemValues.get(index));
paragraph.add(Chunk.NEWLINE);
}
return paragraph;
}
问题出现时带有很长的“价值”。结果是:
param1..............value1
param2..............val1, val2
param3..............some long value
which start new line
......但我需要这样的事情:
param1..............value1
param2..............val1, val2
param3..............some long value
....................which start new line
知道怎么做到吗?只有一个让我印象深刻的解决方案是使用PdfPTable。
答案 0 :(得分:1)
您希望最后一行以点开头吗?
param1..............value1
param2..............val1, val2
param3..............some long value
....................which start new line
似乎以下选项看起来更好(最后一行没有点)
param1..............value1
param2..............val1, val2
param3..............some long value
which start new line