Am 27.07.2017 um 17:49 schrieb Esteban R:
I'm working in a project which uses both pdfbox and apache fop 
(https://xmlgraphics.apache.org/fop/)


CreatePDFA (from pdfbox examples) generates different (wrong?) XMP metadata 
when fop is included in the shaded jar. Otherwise (i.e.: if a simple jar is 
generated or if fop is not included, then metadata is ok). The issue seems to 
be related to the services provided by fop (more details below). How can I 
solve it? Is it ok to exclude the services provided by fop from the shaded jar?


You can find a sample project here:

<http://www.filedropper.com/tmpxmpissue>http://www.filedropper.com/tmpxmpissue_1


To reproduce you can use try.sh -included in the project- in a cygwin (Windows 
10) environment -should work on linux- or you can:

mvn clean install

java -jar target/tmp_xmp_issue-1.0-SNAPSHOT.jar  out.pdf "Hello world" 
OpenSans-Regular.ttf
Open out.pdf with PDFDebugger and see the XMPMetadata:
<rdf:li lang="x-default">out.pdf</rdf:li>

If you don't include fop (i.e. use pom.xml.nofop) then you will get:
<rdf:li xml:lang="x-default">out.pdf</rdf:li>^M

The same will happen if you use pom.xml.noservices (which just excludes the 
services provided by fop).


I use java version "1.8.0_112" and pdfbox 2.0.7.


In Serializer, the namespace is set with

esimple.setAttributeNS(attribute.getNamespace(), attribute.getName(), attribute.getValue());

I traced it, the parameters are

http://www.w3.org/XML/1998/namespace
lang
x-default

so all is good there. It's the transformer who is the problem.

This code in Serializer.java:

Transformer transformer = TransformerFactory.newInstance().newTransformer();

returns a com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl class. If fop is there, it returns a org.apache.xalan.transformer.TransformerIdentityImpl class.

javadoc:
https://docs.oracle.com/javase/7/docs/api/javax/xml/transform/TransformerFactory.html#newInstance()
"The Services API will look for a classname in the file META-INF/services/javax.xml.transform.TransformerFactory in jars available to the runtime."

fop uses xalan-2.7.2.jar and that one has META-INF.services with javax.xml.transform.TransformerFactory, and that one contains org.apache.xalan.processor.TransformerFactoryImpl.

So the question is now, who is right? Is it a bug in xalan or in the calling code, i.e. do we have to set some option?

We could force the default implementation by changing the code in "save" to

Transformer transformer = TransformerFactory.newInstance("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl", null).newTransformer();

Or you can set a system property:

System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");

However maybe this will mess up something in FOP :-(

So I guess the best for you would be to copy the source code of Serializer, and to change the newInstance call as described. Make sure this works for all java versions.

Tilman


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org

Reply via email to