FontFactory(lowagie),Java,尝试使用希腊文正则表达式时获取Java.io.EOFException
我正在使用com.lowagie.text.FontFactory注册要在PDF文件中使用的希腊字体。但是,在注册自己时,我得到了java.io.EOFException。如果有人对此有任何了解,我将不胜感激。谢谢FontFactory(lowagie),Java,尝试使用希腊文正则表达式时获取Java.io.EOFException,java,pdf,fonts,internationalization,itext,Java,Pdf,Fonts,Internationalization,Itext,我正在使用com.lowagie.text.FontFactory注册要在PDF文件中使用的希腊字体。但是,在注册自己时,我得到了java.io.EOFException。如果有人对此有任何了解,我将不胜感激。谢谢 FontFactory.register("/classes/fonts/LiberationSans-Regular.ttf","Greek-Regular"); 错误堆栈: ExceptionConverter: java.io.EOFException at com.
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)
异常转换器:java.io.EOFException
在com.lowagie.text.pdf.RandomAccessFileOrArray.readFully上(未知来源)
在com.lowagie.text.pdf.RandomAccessFileOrArray.readFully上(未知来源)
位于com.lowagie.text.pdf.TrueTypeFont.readStandardString(未知来源)
位于com.lowagie.text.pdf.TrueTypeFont.getAllNames(未知来源)
位于com.lowagie.text.pdf.TrueTypeFont.process(未知来源)
网址:com.lowagie.text.pdf.TrueTypeFont。(来源不明)
位于com.lowagie.text.pdf.BaseFont.getAllFontNames(未知来源)
位于com.lowagie.text.FontFactoryImp.register(未知源)
位于com.lowagie.text.FontFactory.register(未知源)
位于com.gxs.activefoundation.delegate.DefaultPdfReportDelegateImpl。(DefaultPdfReportDelegateImpl.java:212)
您的问题无效,原因如下:
com.Lowagie
包中知道的Lowagie)。这意味着您使用的是一个过时版本的iText,其中包含大量已知的bug,这些bug在过去五年中已被修复。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);
请注意,解放Sans并不像您所说的那样是希腊字体。它是一种包含许多字形的字体,其中包括希腊字母表中的字形。还要注意的是,在我的示例中,您可能希望将中的“Cp1253”
替换为BaseFont.IDENTITY\u H
(这将产生更多经得起未来考验的PDF)
长话短说:我们建议人们不要使用旧版本的iText是有原因的。请阅读了解更多信息。您是否代表GXS(OpenText)为MindTree工作?