2017-08-01 96 views
1

我试图将.fo文件转换为PDF/a与Apache FOP 2.1与文档中给出的exemple代码。我设法给helloworld.fo文件转换成PDF,但是,当我试图把它转换成PDF/A文件,我得到这个错误:FO到PDF/a转换与Apache FOP Java库

org.apache.fop.pdf.PDFConformanceException: For PDF/A-1a, all fonts, even the base 14 fonts, have to be embedded! Offending font: /Helvetica

这就是为什么我在fop.xconf文件试图嵌入字体:

<fonts> 

    <font kerning="yes" embed-url="C:/Users/thinkpad/workspace/FopConverter/Fonts/arial.ttf" name="Arial"> 
     <font-triplet name="Arial" style="normal" weight="700"/> 
    </font> 
    <font kerning="yes" embed-url="C:/Users/thinkpad/workspace/FopConverter/Fonts/arialbd.ttf" name="Arial Bold"> 
     <font-triplet name="Arial" style="normal" weight="bold"/> 
    </font> 
    <font kerning="yes" embed-url="C:/Users/thinkpad/workspace/FopConverter/Fonts/ariali.ttf" name="Arial Italique"> 
     <font-triplet name="Arial" style="italic" weight="700"/> 
    </font> 
    <font kerning="yes" embed-url="C:/Users/thinkpad/workspace/FopConverter/Fonts/arialbi.ttf" name="Helvetica Bold Italique"> 
     <font-triplet name="Arial" style="italic" weight="bold"/> 
    </font> 

    <directory>C:\Users\thinkpad\workspace\FopConverter\Fonts</directory> 
    <directory>C:\Users\thinkpad\workspace\FopConverter\Fonts\ghostFonts</directory> 

    <substitutions> 
    <substitution> 
     <from font-family="Helvetica" font-weight="700..900"/> 
     <to font-family="Arial"/> 
    </substitution> 
    </substitutions> 
    <auto-detect/> 
    </fonts> 

但即使这样做之后,我仍然有同样的错误:org.apache.fop.pdf.PDFConformanceException: For PDF/A-1a, all fonts, even the base 14 fonts, have to be embedded! Offending font: /Helvetica

我也试图通过在加入font-family="Helvetica" font-weight="normal" font-style="normal"修改,因为一些forum topic说这样做,但它没有改变任何东西。

请帮我解决我的嵌入字体错误。感谢您阅读此主题。

[编辑]: 这里是整个错误消息:

FOP ExampleFO2PDF 

Preparing... 
Input: XSL-FO (.\xml\fo\helloworld.fo) 
Output: PDF (.\out\ResultFO2PDF.pdf) 

Transforming... 
août 07, 2017 11:26:49 AM org.apache.fop.events.LoggingEventListener processEvent 
INFOS: Rendered page #1. 
org.apache.fop.pdf.PDFConformanceException: For PDF/A-1b, all fonts, even the base 14 fonts, have to be embedded! Offending font: /Helvetica 
    at org.apache.fop.pdf.PDFFont.validate(PDFFont.java:170) 
    at org.apache.fop.pdf.PDFFont.output(PDFFont.java:179) 
    at org.apache.fop.pdf.PDFDocument.outputIndirectObject(PDFDocument.java:1053) 
    at org.apache.fop.pdf.PDFDocument.streamIndirectObject(PDFDocument.java:1018) 
    at org.apache.fop.pdf.PDFDocument.output(PDFDocument.java:994) 
    at org.apache.fop.pdf.PDFDocument.outputTrailer(PDFDocument.java:1097) 
    at org.apache.fop.render.pdf.PDFDocumentHandler.endDocument(PDFDocumentHandler.java:191) 
    at org.apache.fop.render.intermediate.util.IFDocumentHandlerProxy.endDocument(IFDocumentHandlerProxy.java:187) 
    at org.apache.fop.render.intermediate.IFRenderer.stopRenderer(IFRenderer.java:295) 
    at org.apache.fop.area.RenderPagesModel.endDocument(RenderPagesModel.java:265) 
    at org.apache.fop.area.AreaTreeHandler.endDocument(AreaTreeHandler.java:342) 
    at org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:170) 
    at org.apache.xalan.transformer.TransformerIdentityImpl.endDocument(TransformerIdentityImpl.java:963) 
    at org.apache.xerces.parsers.AbstractSAXParser.endDocument(Unknown Source) 
    at org.apache.xerces.impl.XMLDocumentScannerImpl.endEntity(Unknown Source) 
    at org.apache.xerces.impl.XMLEntityManager.endEntity(Unknown Source) 
    at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source) 
    at org.apache.xerces.impl.XMLEntityScanner.skipSpaces(Unknown Source) 
    at org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dispatch(Unknown Source) 
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) 
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) 
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) 
    at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:485) 
    at ConverterFO2PDFa.convertFO2PDF(ConverterFO2PDFa.java:104) 
    at ConverterFO2PDFa.main(ConverterFO2PDFa.java:154) 
+0

您是否收到其他警告/错误消息?如果您尝试生成“正常”PDF,是否会收到错误警告/错误消息? – lfurini

+1

如果我尝试使用此配置文件从'helloworld.fo'例子中生成一个正常的PDF,我不会收到任何错误或警告。我编辑了我的问题,向您展示整个PDF/a转换错误消息。 –

回答

0

我能够创建一个PDF /使用相同的例子文件一些变化后A输出:

  1. 输入的FO文件中,我明确地添加了font-family="Helvetica"(或您最喜欢的字体系列),它影响了所有文本

    如果没有此设置,即使FOP默认使用Helvetica,但没有设置font-family,它显然无法找到它的配置。

  2. 配置文件

    ,我绘制了Helvetica字体家族现有的字体,例如Arial字体

    <font kerning="yes" embed-url="/Library/Fonts/arial.ttf"> 
        <font-triplet name="Helvetica" style="normal" weight="normal"/> 
    </font> 
    
  3. Java代码,我配置FOP使用我的配置文件和用户代理以启用辅助功能

    import org.apache.avalon.framework.configuration.Configuration; 
    import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; 
    import org.apache.fop.apps.FopFactoryBuilder; 
    
    ... 
    DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); 
    Configuration cfg = cfgBuilder.buildFromFile(new File("/Users/lfurini/fop.xconf")); 
    FopFactoryBuilder fopFactoryBuilder = new FopFactoryBuilder(new File(".").toURI()).setConfiguration(cfg); 
    FopFactory fopFactory = fopFactoryBuilder.build(); 
    
    FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); 
    // configure foUserAgent as desired 
    foUserAgent.setAccessibility(true); 
    foUserAgent.getRendererOptions().put("pdf-a-mode", "PDF/A-1b"); 
    ... 
    
+0

您的解决方案对'helloworld.fo'有效,但对于带有多个策略的'.fo'不够。我向FOP社区询问了这个案例的相同问题:这里是http://apache-fop.1065347.n5.nabble.com/To-PDF-a-Conversion-without-licensed-fonts-java-td45365 .html。然而,我选择另一个图书馆比FOP转换我的文档,因为它需要太多的工作。感谢您的帮助。 –