我使用ittext在我的java应用程序生成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;
}
长"value"出现问题。结果是:
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。
您希望最后一行以点开始吗?
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