AEM 6.0 SVG in PDF generation | Community
Skip to main content
nestor_de_dios1
January 4, 2016
Solved

AEM 6.0 SVG in PDF generation

  • January 4, 2016
  • 3 replies
  • 1201 views

I'm trying to add a SVG graph into a PDF file using the OOTB PDF generation of AEM, but it raises this exception:

 

java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal

  at java.lang.ClassLoader.defineClass1(Native Method)

  at java.lang.ClassLoader.defineClass(Unknown Source)

  at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl. java:2297)

  at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringI mpl.java:1519)

  at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)

  at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl. java:1973)

  at java.lang.ClassLoader.loadClass(Unknown Source)

  at org.apache.batik.dom.svg.SVGDOMImplementation.createDocument(SVGDOMImplementation.java:14 9)

  at org.apache.fop.fo.extensions.svg.SVGDOMContentHandlerFactory$Handler.startElement(SVGDOMC ontentHandlerFactory.java:128)

  at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:308)

  at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)

  at org.apache.cocoon.xml.sax.AbstractSAXPipe.startElement(AbstractSAXPipe.java:97)

  at com.day.cq.wcm.webservicesupport.impl.rewriter.ServicesPingTransformer.startElement(Servi cesPingTransformer.java:142)

  at org.apache.cocoon.xml.sax.AbstractSAXPipe.startElement(AbstractSAXPipe.java:97)

  at com.adobe.cq.media.publishing.dps.impl.rewriter.PathRewriterTransformer.startElement(Path RewriterTransformer.java:133)

  at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.closeStartTag(Unknown Source)

  at com.sun.org.apache.xml.internal.serializer.ToSAXHandler.flushPending(Unknown Source)

  at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.startElement(Unknown Source)

  at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.startElement(Unknown Source)

  .....

 

As I could see, the missing class is already defined in the bundle com.day.commons.osgi.wrapper.fop (the wrapper for apache FOP).

 

There are any kind of workaround to fix that?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by nestor_de_dios1

I already found a workaround to fix the AEM issue.

The origin of the issue was regarding to the Apache Batik library, used by Apache FOP library which is the OOTB library used by AEM to generate PDF files.

The Batik library imports the package org.w3c.dom, and this package is exported by the AEM system bundle (is defined in a bundle fragment called "org.apache.sling.fragment.xml").

So, the problem was: the batik library reference the class org.w3c.dom.ElementTraversal, but this class is missing in the AEM fragment that exports the org.w3c.dom package.

Then, the workaround was: create a new bundle fragment as a fragment of the system bundle including the missing class (This class comes from the "batik-ext" library).

Here is the bundle manifest:

Manifest-Version: 1.0
Built-By: Nestor
Bundle-ManifestVersion: 2
Bundle-Name: XML Extension Bundle
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: org.w3c.dom;version="1.0"
Fragment-Host: system.bundle; extension:=framework
 

3 replies

smacdonald2008
Level 10
January 4, 2016

Are you following any online documentation - can you point the community to that please. 

nestor_de_dios1
January 5, 2016

I'm following the examples in the apache FOP page:
https://xmlgraphics.apache.org/fop/dev/svg.html

The error can be reproduced by copying any piece of the SVG example from this file:
https://xmlgraphics.apache.org/fop/dev/fo/embedding.fo.pdf
And put it into the default AEM xsl transformation at:
/libs/wcm/core/content/pdf/page2fo.xsl

 

All the required third party libraries to put to work apache FOP in AEM are wrapped into the bundle "com.day.commons.osgi.wrapper.fop".

This bundle also includes the missing class, but I think it can't be referenced due to the bundle defines the containing package of that class (org.w3c.dom) as an external import in the POM, and the bundle where that package is exported (org.apache.felix.framework) does not contains the class.

nestor_de_dios1
nestor_de_dios1AuthorAccepted solution
January 19, 2016

I already found a workaround to fix the AEM issue.

The origin of the issue was regarding to the Apache Batik library, used by Apache FOP library which is the OOTB library used by AEM to generate PDF files.

The Batik library imports the package org.w3c.dom, and this package is exported by the AEM system bundle (is defined in a bundle fragment called "org.apache.sling.fragment.xml").

So, the problem was: the batik library reference the class org.w3c.dom.ElementTraversal, but this class is missing in the AEM fragment that exports the org.w3c.dom package.

Then, the workaround was: create a new bundle fragment as a fragment of the system bundle including the missing class (This class comes from the "batik-ext" library).

Here is the bundle manifest:

Manifest-Version: 1.0
Built-By: Nestor
Bundle-ManifestVersion: 2
Bundle-Name: XML Extension Bundle
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: org.w3c.dom;version="1.0"
Fragment-Host: system.bundle; extension:=framework