java - 我创建的 pdf 文件中丢失了空格(pdfbox 和 itextpdf)

标签 java indentation pdfbox itextpdf

我正在使用 pdfbox 和 itextpdf 创建 pdf 格式的非常简单的发票。

我们正在 java 之外的 erp 系统中创建原始发票文本文件 - 所以我唯一要做的就是将文本文件与 (pdf) 模板结合起来。 (这不是问题。;))

它工作正常 - 但我现在在 pdf 中发现一个缩进错误:在表格标题之后,缩进出错(删除了一个前导空格)。

我做错了什么?

这就是生成示例 pdf 的代码:

final File outputFile = this.createTmpFile();
final Document document = new Document(PageSize.A4);
PdfWriter.getInstance(document, new FileOutputStream(outputFile));
document.open();
final StringBuffer testText = new StringBuffer();
testText.append("                                                                 21.12.2012\n");
testText.append("\n");
testText.append("\n");
testText.append("\n");
testText.append("Invoice\n");
testText.append("\n");
testText.append("\n");
testText.append("Amount  Description                                         CUR       Price\n");
testText.append("===========================================================================\n");
testText.append("\n");
testText.append(" 1      Order #E41141454 from 01.01.2012:                   EUR       21,21\n");
testText.append("        nice text, nice text, nice text, nice text,\n");
testText.append("        nice text, nice text, nice text, nice text,\n");
testText.append("\n");
testText.append("        Status: online\n");
final Paragraph para = new Paragraph();
para.setFont(new Font(FontFamily.COURIER, 8.6f));
para.setAlignment(Element.ALIGN_UNDEFINED);
para.setLeading(1.2f, 1.2f);
final String t = testText.toString();
para.add(t);
document.add(para);
document.close();

SampleInvoice

最佳答案

已解决!

我们从 itextpdf 5.0.6 更新到 5.4.0

关于java - 我创建的 pdf 文件中丢失了空格(pdfbox 和 itextpdf),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15091339/

相关文章:

java - 在 Ubuntu 终端中运行可执行 jar 时获取错误文件。<init>

java - 使用 slick 和 java 来玩框架

visual-studio-code - 如何防止 VSCode 自动删除我的缩进

indentation - 如何在 IDLE 中删除多行制表符缩进?

java - 如何在PDFBox中绘制三角形

Java SHA 不工作。哈希值不等于字符串。我的编码有问题吗?

java - 没有调用 timeToken 的 successCallback

java - 更改文件中的每一行 - Java

java - 使用 PDFBox 与 Tj 和 TJ 运算符(operator)合作

java - 更改现有 PDF 文档的方向(纵向/横向)