我正在使用 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();
最佳答案
已解决!
我们从 itextpdf 5.0.6 更新到 5.4.0
关于java - 我创建的 pdf 文件中丢失了空格(pdfbox 和 itextpdf),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15091339/