【发布时间】:2018-06-24 18:09:26
【问题描述】:
我的 Spring Boot Java 应用程序使用 apache pdf box library {version 2.0.6} 来生成 pdf。我希望十进制值右对齐。这意味着所有小数点应该在同一垂直线上对齐。我还附上了截图。
stream.beginText();
stream.newLineAtOffset(xCordinate, yCordinate);
stream.showText(String.valueOf(item.getQuantity()));
List<String> resultList = processTextData(TextUtil.isEmpty(item.getDescription()) ? "-" : item.getDescription());
int y = 0;
int x = 50;
int tempYcordinate = yCordinate;
for (String string : resultList) {
stream.newLineAtOffset(x, y);
stream.showText(processStringForPdf(string));
x = 0;
y = -8;
}
tempYcordinate = tempYcordinate - (8 * resultList.size());
stream.endText();
stream.beginText();
stream.newLineAtOffset(285, yCordinate);
stream.showText("$" + NumberFormat.getInstance(Locale.US).format(Util.round(item.getUnitPrice())));
stream.newLineAtOffset(65, 0);
stream.showText("$" + NumberFormat.getInstance(Locale.US).format(Util.round(item.getExtPrice())));
stream.endText();
yCordinate = tempYcordinate;
【问题讨论】:
-
你尝试了什么,是什么阻止了你? Pdfbox 甚至不包含像屏幕截图中那样自动布局表格的选择,因此您必须已经完成了一些布局,因此知道如何做到这一点。还是您使用了未提及的插件?
-
对齐方式取决于相邻的属性{列,这里是单价和分机价格}。所以我也想处理这个问题。如果一个数量在小数点前 4 位,另一个在小数点前 3 位。对齐被破坏了。我没有使用任何插件
-
你听说过
PDFont.getStringWidth()吗?
标签: java apache pdf spring-boot pdfbox