IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

XSLT 1.0 pdf generation with apache FOP Options · View
siva_pallapu
Posted: Saturday, December 12, 2015 6:36:47 PM
Rank: Newbie

Joined: 12/12/2015
Posts: 1
Hi All,

I am new to XSLT FO and in one of requirements I need to generate the pdf from XSLT FO using Apache FOP. I was able to design the form with XSLT 1.0 and using Apache FOP 2.0 for generating pdf.

1. Below is the classpath I am setting
set classpath=.;D:/libs/barcode4j-2.1.jar;D:/libs/barcode4j-fop-ext-2.0.jar;D:/libs/avalon-framework-4_2_0.jar;D:/libs/commons-cli-1.0.jar;D:/fop-2.0-bin/fop-2.0/build/fop.jar;D:/libs/serializer-2.7.0.jar;D:/libs/xalan- 2.7.0.jar;D:/libs/xercesImpl-2.7.1.jar;D:/libs/xml-apis-1.3.04.jar;D:/libs/batik-all-1.7.jar;

2. command I am using to generate the pdf is : java -jar fop.jar -xml D:/json/person.xml -xsl D:/altova_xslt_file/Barcode4J_test.xslt -pdf D:/altova_xslt_file/Barcode4J_test.pdf

3. I am using the below names in the XSLT

xmlns:barcode="http://barcode4j.krysalis.org/ns" extension-element-prefixes="barcode"
4. Barcode generating piece
<fo:block>
<fo:instream-foreign-object>
<barcode:barcode xmlns:barcode="http://barcode4j.krysalis.org/ns" message="my message" orientation="90">
<barcode:code128>
<barcode:height>8mm</barcode:height>
</barcode:code128>
</barcode:barcode>
</fo:instream-foreign-object>
</fo:block>

5. Exception that I am getting is

D:\fop-2.0-bin\fop-2.0\build>java -jar fop.jar -xml D:/json/person.xml -xsl D:/altova_xslt_file/Barcode4J_test.xslt -pdf D:/altova_xslt_file/Barcode4J_test.pdf
Dec 12, 2015 11:10:18 AM org.apache.fop.fo.FOTreeBuilder fatalError
SEVERE: org.xml.sax.SAXParseException; systemId: file:/D:/altova_xslt_file/Barcode4J_test.xslt; lineNumber: 64; columnNumber: 66; javax.xml.transform.TransformerException: java.lang.ClassNotFoundExcep
tion: ns
Dec 12, 2015 11:10:18 AM org.apache.fop.cli.Main startFOP
SEVERE: Exception
org.apache.fop.apps.FOPException: javax.xml.transform.TransformerException: java.lang.ClassNotFoundException: ns
javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: java.lang.ClassNotFoundException: ns
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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.fop.cli.Main.startFOPWithDynamicClasspath(Main.java:143)
at org.apache.fop.cli.Main.main(Main.java:219)
Caused by: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: java.lang.ClassNotFoundException: ns
at org.apache.xalan.extensions.ExtensionHandlerJavaPackage.processElement(ExtensionHandlerJavaPackage.java:491)
at org.apache.xalan.templates.ElemExtensionCall.execute(ElemExtensionCall.java:232)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2281)
at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1367)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1284)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1262)
at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:285)
... 8 more
Caused by: javax.xml.transform.TransformerException: java.lang.ClassNotFoundException: ns
at org.apache.xalan.extensions.ExtensionHandlerJavaPackage.processElement(ExtensionHandlerJavaPackage.java:481)
... 32 more
Caused by: java.lang.ClassNotFoundException: ns
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)


Please help me in resolving the issue.

Thanks in Advance,
Siva
Irian
Posted: Tuesday, December 15, 2015 3:25:25 PM
Rank: Member

Joined: 10/23/2013
Posts: 18
Hi,

I'm fairly sure this approach works, since I've used it myself in various reports, make sure you are setting the barcode configuration bits in a user defined block since these should not be touched by stylevision during the XSLT file generation.


Judging by the error you get it appears there are problems loading the additional jar required by fop to generate the barcode output.


As a first try I suggest you to use the fop.bat script (or the bash equivalent if you are on linux), this way you are sure that all the fop classpath requirements are correctly configured, to add the barcode extension in 2.0 it's sufficient to drop the jar in the lib dir and the script is able to pick it up.

If this still does not work it might be an issue with the barcode library since I do not know if it has been updated for fop 2.0 and I've not tested that configuration yet; if you can, try using a different version of fop to generate your report and see if it works.
Irian
Posted: Wednesday, December 16, 2015 9:02:49 AM
Rank: Member

Joined: 10/23/2013
Posts: 18
I've had a little free time this morning and I put together a small example for you, hope it is of help.

I've tested this example with a basic fop 2.0 installation using the default fop.bat

The only modification I made to the standard fop installation is that I dropped the file: barcode4j-fop-ext-complete.jar in the lib folder

As it is this example works without problems even when invoked directly from StyleVision

File Attachment(s):
BarcodeExample.zip (3kb) downloaded 1,061 time(s).


Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.