【问题标题】:Lost spaces in my created pdfs (pdfbox & itextpdf)我创建的 pdf 文件中丢失了空格(pdfbox 和 itextpdf)
【发布时间】:2013-02-26 14:16:46
【问题描述】:

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

【问题讨论】:

  • 听起来像是这个问题的重复:stackoverflow.com/questions/14981437/…(在最近的版本中解决了这个问题;您应该提及您使用的是哪个版本的 iText)
  • 是的,可能是同一个原因。版本是 itextpdf 5.0.6 - 我切换到 5.4.0,现在可以正常工作了。但我认为,在去年创建了大约 100 万份 pdf - 我们必须看到过去的错位。

标签: java indentation pdfbox itextpdf


【解决方案1】:

解决了

我们从 itextpdf 5.0.6 更新到 5.4.0

【讨论】:

    猜你喜欢
    • 2011-11-30
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-18
    相关资源
    最近更新 更多