簡體   English   中英

我創建的pdf中的空格丟失(pdfbox&itextpdf)

[英]Lost spaces in my created pdfs (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();

樣品發票

解決了

我們從itextpdf 5.0.6更新到5.4.0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM