FOP PDF/A-3b 不允许嵌入文件

FOP PDF/A-3b does not allow embedded files

我正在尝试使用 fop 2.1 将 xml 文件嵌入到 PDF/A3-b 文件中并得到以下答案:

SCHWERWIEGEND: Exception
org.apache.fop.apps.FOPException: PDF/A-3b does not allow embedded files.
org.apache.fop.pdf.PDFConformanceException: PDF/A-3b does not allow embedded files.
    at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:288)
    at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:115)
    at org.apache.fop.cli.Main.startFOP(Main.java:186)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.fop.cli.Main.startFOPWithDynamicClasspath(Main.java:143)
    at org.apache.fop.cli.Main.main(Main.java:219)
Caused by: org.apache.fop.pdf.PDFConformanceException: PDF/A-3b does not allow embedded files.
    at org.apache.fop.pdf.PDFProfile.verifyEmbeddedFilesAllowed(PDFProfile.java:336)
    at org.apache.fop.render.pdf.PDFRenderingUtil.addEmbeddedFile(PDFRenderingUtil.java:651)
    at org.apache.fop.render.pdf.PDFDocumentHandler.handleExtensionObject(PDFDocumentHandler.java:318)
    at org.apache.fop.render.intermediate.util.IFDocumentHandlerProxy.handleExtensionObject(IFDocumentHandlerProxy.java:192)
    at org.apache.fop.render.intermediate.IFRenderer.processOffDocumentItem(IFRenderer.java:325)
    at org.apache.fop.area.RenderPagesModel.handleOffDocumentItem(RenderPagesModel.java:232)
    at org.apache.fop.area.AreaTreeHandler.addOffDocumentItem(AreaTreeHandler.java:376)
    at org.apache.fop.area.AreaTreeHandler.wrapAndAddExtensionAttachments(AreaTreeHandler.java:245)
    at org.apache.fop.area.AreaTreeHandler.startAbstractPageSequence(AreaTreeHandler.java:234)
    at org.apache.fop.area.AreaTreeHandler.startPageSequence(AreaTreeHandler.java:222)
    at org.apache.fop.fo.DelegatingFOEventHandler.startPageSequence(DelegatingFOEventHandler.java:109)
    at org.apache.fop.accessibility.fo.FO2StructureTreeConverter.startPageSequence(FO2StructureTreeConverter.java:142)
    at org.apache.fop.fo.pagination.PageSequence.startOfNode(PageSequence.java:121)
    at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:337)
    at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:179)
    at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1073)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.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.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:485)
    at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:285)
    ... 8 more

---------

org.apache.fop.pdf.PDFConformanceException: PDF/A-3b does not allow embedded files.
    at org.apache.fop.pdf.PDFProfile.verifyEmbeddedFilesAllowed(PDFProfile.java:336)
    at org.apache.fop.render.pdf.PDFRenderingUtil.addEmbeddedFile(PDFRenderingUtil.java:651)
    at org.apache.fop.render.pdf.PDFDocumentHandler.handleExtensionObject(PDFDocumentHandler.java:318)
    at org.apache.fop.render.intermediate.util.IFDocumentHandlerProxy.handleExtensionObject(IFDocumentHandlerProxy.java:192)
    at org.apache.fop.render.intermediate.IFRenderer.processOffDocumentItem(IFRenderer.java:325)
    at org.apache.fop.area.RenderPagesModel.handleOffDocumentItem(RenderPagesModel.java:232)
    at org.apache.fop.area.AreaTreeHandler.addOffDocumentItem(AreaTreeHandler.java:376)
    at org.apache.fop.area.AreaTreeHandler.wrapAndAddExtensionAttachments(AreaTreeHandler.java:245)
    at org.apache.fop.area.AreaTreeHandler.startAbstractPageSequence(AreaTreeHandler.java:234)
    at org.apache.fop.area.AreaTreeHandler.startPageSequence(AreaTreeHandler.java:222)
    at org.apache.fop.fo.DelegatingFOEventHandler.startPageSequence(DelegatingFOEventHandler.java:109)
    at org.apache.fop.accessibility.fo.FO2StructureTreeConverter.startPageSequence(FO2StructureTreeConverter.java:142)
    at org.apache.fop.fo.pagination.PageSequence.startOfNode(PageSequence.java:121)
    at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:337)
    at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:179)
    at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1073)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.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.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:485)
    at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:285)
    at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:115)
    at org.apache.fop.cli.Main.startFOP(Main.java:186)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.fop.cli.Main.startFOPWithDynamicClasspath(Main.java:143)
    at org.apache.fop.cli.Main.main(Main.java:219)

这是我的 .fo 文件

<?xml version="1.0" encoding="UTF-8"?> 
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" 
         font-family="PT-Sans" font-weight="normal" font-style="normal"
         xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf"> 
    <fo:layout-master-set> 
        <fo:simple-page-master master-name="first" page-height="29.7cm" page-width="21cm" margin-top="0cm" margin-bottom="0cm" margin-left="0cm" margin-right="0cm"> 
            <fo:region-body margin-top="0cm"/> 
            <fo:region-before extent="0cm"/> 
            <fo:region-after extent="0cm"/> 
        </fo:simple-page-master> 
    </fo:layout-master-set> 
    <fo:declarations>
        <pdf:embedded-file src="url(path/to/file/file.xml)"/>
    </fo:declarations>
    <fo:page-sequence master-reference="first"> 
        <fo:flow flow-name="xsl-region-body"> 
            <fo:block-container width="100%" height="100%" break-before="page" text-align="left" font-size="8pt"> 
                <fo:block-container position="absolute" left="1.5cm" top="5cm" height="1cm" width="10cm"> 
                    <fo:block color="#70706f">Some Suff</fo:block> 
                </fo:block-container> 
            </fo:block-container>
        </fo:flow> 
    </fo:page-sequence> 
</fo:root>

fop.xconf 文件已扩展,就像在 fop 的 website 中描述的那样。

最后是我的bash shell

的执行命令
java -jar build/fop.jar -c conf/fop.xconf -fo examples/fofile.fo -pdf examples/pdffile.pdf

使用 -c 执行但没有块工作正常。
在没有 -c 的情况下执行但使用块也可以正常工作。

java -jar build/fop.jar -c conf/fop.xconf 

是 "use exactly this fop.xconv file" 的命令。

我错过了什么吗?

我尝试通过修补 fop 2.1 源 (fop-2.1/src/java) 来绕过它:

*** org/apache/fop/pdf/PDFProfile.java.mod  2016-07-13 16:08:19.621331387 +0200
--- org/apache/fop/pdf/PDFProfile.java  2016-01-07 15:13:29.000000000 +0100
*************** public class PDFProfile {
*** 332,338 ****
      /** Checks if embedded files are allowed. */
      public void verifyEmbeddedFilesAllowed() {
          final String err = "{0} does not allow embedded files.";
!         if (getPDFAMode() != PDFAMode.DISABLED && getPDFAMode() != PDFAMode.PDFA_3A && getPDFAMode() != PDFAMode.PDFA_3B && getPDFAMode() != PDFAMode.PDFA_3U ) {
              throw new PDFConformanceException(format(err, getPDFAMode()));
          }
          if (isPDFXActive()) {
--- 332,338 ----
      /** Checks if embedded files are allowed. */
      public void verifyEmbeddedFilesAllowed() {
          final String err = "{0} does not allow embedded files.";
!         if (isPDFAActive()) {
              throw new PDFConformanceException(format(err, getPDFAMode()));
          }
          if (isPDFXActive()) {

然后编译

javac -cp ../../build/fop.jar org/apache/fop/pdf/PDFProfile.java

备份你原来的jar

cp ../../build/fop.jar ../../build/fop.jar.orig

并将新的 class 添加到 jar

jar -uf ../../build/fop.jar org/apache/fop/pdf/PDFProfile.class

虽然很脏,但我也添加了问题FOP-2625

编辑

问题已由 Simon Steiner 在 fop trunk 版本中修复。