1

我正在使用 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();

样品发票

4

1 回答 1

1

解决了

我们从 itextpdf 5.0.6更新到5.4.0

于 2013-02-28T12:39:44.440 回答