当字体自动检测启用时,FOP给出NoSuchMethodError

时间:2017-01-06 08:19:58

标签: pdf pdf-generation apache-fop

从Apache FOP生成PDF时,我收到了波纹管错误,

  FopFactory fopFactory = FopFactory.newInstance(new File("/Users/vinurip/cloud/Stripe/Full/pdfboxtut/src/main/resources/fop.xconf"));
    OutputStream out = new BufferedOutputStream(new FileOutputStream(new File(outFile)));
    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);

OutFile是一个空的pdf文件位置。 fop.xconf与FOP源中的相同

  Exception in thread "main" java.lang.NoSuchMethodError: org.apache.fontbox.cff.CFFFont.getProperty(Ljava/lang/String;)Ljava/lang/Object;
    at org.apache.fop.fonts.truetype.OTFFile.readName(OTFFile.java:134)
    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.autodetect.FontInfoFinder.find(FontInfoFinder.java:254)
    at org.apache.fop.fonts.FontAdder.add(FontAdder.java:63)
    at org.apache.fop.fonts.FontDetectorFactory$DefaultFontDetector.detect(FontDetectorFactory.java:105)
    at org.apache.fop.fonts.FontManager.autoDetectFonts(FontManager.java:229)
    at org.apache.fop.fonts.DefaultFontConfigurator.configure(DefaultFontConfigurator.java:82)
    at org.apache.fop.render.PrintRendererConfigurator.getCustomFontCollection(PrintRendererConfigurator.java:147)
    at org.apache.fop.render.PrintRendererConfigurator.setupFontInfo(PrintRendererConfigurator.java:127)
    at org.apache.fop.render.intermediate.IFUtil.setupFonts(IFUtil.java:170)
    at org.apache.fop.render.intermediate.IFRenderer.setupFontInfo(IFRenderer.java:187)
    at org.apache.fop.area.RenderPagesModel.<init>(RenderPagesModel.java:75)
    at org.apache.fop.area.AreaTreeHandler.setupModel(AreaTreeHandler.java:135)
    at org.apache.fop.area.AreaTreeHandler.<init>(AreaTreeHandler.java:105)
    at org.apache.fop.render.RendererFactory.createFOEventHandler(RendererFactory.java:350)
    at org.apache.fop.fo.FOTreeBuilder.<init>(FOTreeBuilder.java:107)
    at org.apache.fop.apps.Fop.createDefaultHandler(Fop.java:104)
    at org.apache.fop.apps.Fop.<init>(Fop.java:78)
    at org.apache.fop.apps.FOUserAgent.newFop(FOUserAgent.java:182)
    at org.apache.fop.apps.FopFactory.newFop(FopFactory.java:220)
    at foptest.fo2PDF(foptest.java:73)
    at foptest.main(foptest.java:57)

只有在启用字体自动检测时才会出现此问题

2 个答案:

答案 0 :(得分:0)

您可以使用搜索引擎找到一些信息 - 例如。 https://qnalist.com/questions/6434450/pdfbox-2-0-and-batik - 虽然这些不是很有用......

我的解决方法是使用<directory recursive="true">/usr/share/fonts</directory>而不是<auto-detect />

答案 1 :(得分:0)

由于Apache FOP和Apache PDFBox / FontBox之间的Maven依赖性不匹配,我遇到了这个问题。

我在撰写本文时将项目的pom.xml迁移到最新的依赖版本,从而解决了这个问题:

<dependency>
  <groupId>org.apache.xmlgraphics</groupId>
   <artifactId>fop</artifactId>
   <version>2.2</version>
</dependency>
<dependency>
   <groupId>org.apache.pdfbox</groupId>
   <artifactId>pdfbox</artifactId>
   <version>2.0.9</version>
</dependency>
<dependency>
  <groupId>org.apache.pdfbox</groupId>
  <artifactId>fontbox</artifactId>
  <version>2.0.9</version>
</dependency>

要迁移到Apache FOP 2.2,请按照embedding guidelinesmigration guideslines

进行操作