问题
I am attempting to convert a svg image to pdf using the Batik SVG toolkit on Ubuntu-11.10. I have Batik 1.7 and Fop 0.95 installed. When running the following in the terminal:
java -jar /usr/java/share/batik-rasterizer.jar -m application/pdf /home/user/Batik_Test/colors.svg
-scriptSecurityOff
I get the following error:
Error while converting files:
Error: cannot access transcoder for image of type application/pdf
The one thing I did notice was that the file 'pdf-transcoders.jar' was not on the machine so I added that to /usr/share/java on the off chance that was the problem but that did not make a difference.
I would appreciate any help from anyone out there with experience using Batik on ubuntu. What am I missing?
-J
回答1:
if you have the java executable batik-rasterizer.jar in /usr/java/share/ directory, you can create a dir named lib in this same path (/usr/java/share/)
so to have
/usr/java/share/lib
in this latest dir (lib) you will copy the pdf-transcoder.jar so to have
/usr/java/share/lib/pdf-transcoder.jar
anyway, you need also other libs in addition to this, so, it is better for you, copy the whole content of lib directory contained in batik binary distribution zip file
- http://mirror.nohup.it/apache//xmlgraphics/batik/batik-1.7.zip
to
/usr/java/share/lib/
only *content*, not lib, if you want copy the whole lib at once, you need to put in
/usr/java/share/
回答2:
If you are executing Batik from fedora using the .jar file it is quite painful due to the java ignoring the -classpath flag. I assume batik in /usr/share/java Select the location according to your system One solution could be the following: create a scratch directory (I assume you are superuser, anyway you always can sudo commands)
mkdir scratch
cd scratch
jar -xf /usr/share/java/batik-rasterizer.jar
This output the content of the jar file into scratch, then create a MANIFEST.MF file or take the output one from the dump
cp META-INF/MANIFEST.MF .
Now edit the MANIFEST.MF file (I like to use vi, anyone use their preferred one)
vi MANIFEST.MF
Add a Class-Path: line into the MANIFEST.MF as for example:
Class-Path: batik-all.jar xmlgraphics-commons.jar xml-commons-apis-ext.jar pdf-transcoder.jar avalon-framework.jar avalon-framework-api.jar apache-commons-logging.jar apache-commons-io.jar
Then close the file and recreate the jar file
jar cmf MANIFEST.MF /usr/share/java/batik-rasterizer.jar org/*
Include all jar that batik has nested classes
Then you can use it!
java -jar /usr/share/java/batik-rasterizer.jar -scriptSecurittyOff -m image/png -d image.png image.svg
for example, and that's it!
来源:https://stackoverflow.com/questions/8434416/converting-svg-to-pdf-with-batik-not-working-on-ubuntu-11-10