【问题标题】:FontFactory (lowagie), Java, getting java.io.EOFException when trying to use Greek-RegularFontFactory (lowagie),Java,尝试使用 Greek-Regular 时出现 java.io.EOFException
【发布时间】:2014-08-04 22:03:35
【问题描述】:

我正在使用 com.lowagie.text.FontFactory 注册希腊字体以在 PDF 文件中使用。但是,在注册自己时,我得到了 java.io.EOFException。如果有人对此有任何见解,我将不胜感激。谢谢

FontFactory.register("/classes/fonts/LiberationSans-Regular.ttf","Greek-Regular");

错误堆栈:

ExceptionConverter: java.io.EOFException
    at com.lowagie.text.pdf.RandomAccessFileOrArray.readFully(Unknown Source)
    at com.lowagie.text.pdf.RandomAccessFileOrArray.readFully(Unknown Source)
    at com.lowagie.text.pdf.TrueTypeFont.readStandardString(Unknown Source)
    at com.lowagie.text.pdf.TrueTypeFont.getAllNames(Unknown Source)
    at com.lowagie.text.pdf.TrueTypeFont.process(Unknown Source)
    at com.lowagie.text.pdf.TrueTypeFont.<init>(Unknown Source)
    at com.lowagie.text.pdf.BaseFont.getAllFontNames(Unknown Source)
    at com.lowagie.text.FontFactoryImp.register(Unknown Source)
    at com.lowagie.text.FontFactory.register(Unknown Source)
    at com.gxs.activefoundation.delegate.DefaultPdfReportDelegateImpl.<clinit>(DefaultPdfReportDelegateImpl.java:212)

【问题讨论】:

  • 您是否代表 GXS (OpenText) 为 MindTree 工作?

标签: java pdf fonts internationalization itext


【解决方案1】:

您的问题无效,原因如下:

  1. 您在代码中使用了我的名字(我是 com.lowagie 软件包中的 Lowagie)。这意味着您使用的是过时的 iText 版本,其中包含大量已知错误,这些错误已在过去五年中得到修复。
  2. 我已在最新版本的 iText 中使用您的代码 sn-p 编写了概念证明 (POC),但无法重现该问题。

对于 POC,我已从该站点下载 LiberationSans-Regular.ttf:http://www.fontsquirrel.com/fonts/Liberation-Sans

我已经复制粘贴了你的代码 sn-p 并且我使用了一个简单的希腊词来编写一个名为 LiberationSans 的小型独立应用程序。生成的 PDF 如下所示:LiberationSans.pdf(请检查它是否显示希腊语中的“新娘”)。

没有遇到异常:

Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("LiberationSans.pdf"));
document.open();
FontFactory.register("resources/fonts/LiberationSans-Regular.ttf","Greek-Regular");
Font f = FontFactory.getFont("Greek-Regular", "Cp1253", true);
Paragraph p = new Paragraph("\u039d\u03cd\u03c6\u03b5\u03c2", f);
document.add(p);

请注意,Liberation Sans 并不是您声称的希腊字体。它是一种包含许多字形的字体,其中是来自希腊字母表的字形。另请注意,您可能希望将我的示例中的 "Cp1253" 替换为 BaseFont.IDENTITY_H(这会产生更多面向未来的 PDF)。

长话短说:我们建议人们不要使用旧版本的 iText 是有原因的。请阅读http://itextpdf.com/salesfaq 了解更多信息。

【讨论】:

    猜你喜欢
    • 2011-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-08
    • 2018-06-24
    • 2011-05-22
    相关资源
    最近更新 更多