Search code examples
xmlapache-foppdfa

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


I am trying to embed a xml file into a PDF/A3-b file with fop 2.1 and get this answer:

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)

Here is my .fo File

<?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>

The fop.xconf file was extended like it is described on the website of fop.

At last the execution command from my bash shell

java -jar build/fop.jar -c conf/fop.xconf -fo examples/fofile.fo -pdf examples/pdffile.pdf

Executing with -c but without the block works fine.
Executing without -c but with the block works also fine.

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

is the command for "use exactly this fop.xconv file".

Am i missing something?


Solution

  • I have a try getting around it by patching in the fop 2.1 source (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()) {
    

    Then compile

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

    backup your original jar

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

    and add your new class to the jar

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

    Quite dirty though, I've also added the issue FOP-2625

    Edit

    Issue was fixed by Simon Steiner in the fop trunk version.