fop 2.1 在 weblogic 服务器上加载字体时达到 EOF

fop 2.1 Reached EOF when loading font on weblogic server

我有一个生成 PDF 文件的网络应用程序。我为此使用 fop 2.1,但有些字符不是默认的 fop 字体。我尝试使用其他字体,以正确打印所有字符。

如果我在我的 PC 上执行的测试类中尝试,一切正常。但是如果应用程序尝试在 weblogic 服务器上做同样的事情,我会收到: java.io.EOFException: 到达 EOF,文件大小=23275952 偏移量=23275954 错误。

我的 fop 配置(我在测试和应用中使用相同的配置):

<fop version="2.1">
    <use-cache>false</use-cache>
    <renderers>
        <renderer mime="application/pdf">
            <fonts>
                <font embed-url="urkunde/ClearSans-Regular.ttf" kerning="yes">
                    <font-triplet name="ClearSans" style="normal" weight="normal" />
                </font>
            </fonts>
        </renderer>
    </renderers>
</fop>

我在服务器尝试加载字体时收到的错误:

Mar 24, 2016 1:07:33 PM org.apache.fop.fonts.truetype.OpenFont readPostScript SEVERE: Unknown PostScript format: 1912630528 Mar 24, 2016 1:07:33 PM org.apache.fop.fonts.LazyFont load SEVERE: Failed to read font metrics file null java.io.EOFException: Reached EOF, file size=23275952 offset=23275954 at org.apache.fop.fonts.truetype.FontFileReader.seekSet(FontFileReader.java:58) at org.apache.fop.fonts.truetype.TTFFile.readName(TTFFile.java:57) at org.apache.fop.fonts.truetype.OpenFont.readFont(OpenFont.java:740) at org.apache.fop.fonts.truetype.OFFontLoader.read(OFFontLoader.java:109) at org.apache.fop.fonts.truetype.OFFontLoader.read(OFFontLoader.java:93) at org.apache.fop.fonts.FontLoader.getFont(FontLoader.java:124) at org.apache.fop.fonts.FontLoader.loadFont(FontLoader.java:108) at org.apache.fop.fonts.LazyFont.load(LazyFont.java:116) at org.apache.fop.fonts.LazyFont.getAscender(LazyFont.java:233) at org.apache.fop.fonts.Font.getAscender(Font.java:118) at org.apache.fop.layoutmgr.BlockLayoutManager.initialize(BlockLayoutManager.java:82) at org.apache.fop.layoutmgr.AbstractLayoutManager.getChildLM(AbstractLayoutManager.java:118) at org.apache.fop.layoutmgr.FlowLayoutManager.getNextKnuthElements(FlowLayoutManager.java:108) at org.apache.fop.layoutmgr.FlowLayoutManager.getNextKnuthElements(FlowLayoutManager.java:69) at org.apache.fop.layoutmgr.PageBreaker.getNextKnuthElements(PageBreaker.java:254) at org.apache.fop.layoutmgr.AbstractBreaker.getNextBlockList(AbstractBreaker.java:752) at org.apache.fop.layoutmgr.PageBreaker.getNextBlockList(PageBreaker.java:180) at org.apache.fop.layoutmgr.PageBreaker.getNextBlockList(PageBreaker.java:160) at org.apache.fop.layoutmgr.AbstractBreaker.doLayout(AbstractBreaker.java:388) at org.apache.fop.layoutmgr.PageBreaker.doLayout(PageBreaker.java:114) at org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(PageSequenceLayoutManager.java:138) at org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.java:267) at org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java:130) at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:360) at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:190) at org.apache.xalan.transformer.TransformerIdentityImpl.endElement(TransformerIdentityImpl.java:1101) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2939) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522) at weblogic.xml.jaxp.WebLogicXMLReader.parse(WebLogicXMLReader.java:133) at weblogic.xml.jaxp.RegistryXMLReader.parse(RegistryXMLReader.java:173) at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)

我也试过其他字体。这在我测试时运行良好,但在服务器上我收到了 NegativeArraySizeException。

我不知道我错过了什么。

有什么建议吗?

我解决了。问题是,字体在耳朵和 war 文件中。如果该字体仅在服务器上,则可以正常工作。

另一种解决方案是在 maven 配置中跳过 ttf 过滤:

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <encoding>UTF-8</encoding>
        <nonFilteredFileExtensions>
            <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
        </nonFilteredFileExtensions>
    </configuration>
</plugin>

使用此配置,您可以将 ttf 保留在 ear/war 包中。