小编Nan*_*ore的帖子

使用 Apache PDFBox 库右对齐 PDF 中的数值

我的 Spring boot Java 应用程序使用 apache pdf box 库 {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;
Run Code Online (Sandbox Code Playgroud)

PDF 的屏幕截图

java apache pdf pdfbox spring-boot

2
推荐指数
1
解决办法
2482
查看次数

标签 统计

apache ×1

java ×1

pdf ×1

pdfbox ×1

spring-boot ×1