3

在一台服务器和我的 Windows 笔记本电脑上,使用这种方法生成 PDF 效果很好:

http://www.databasesandlife.com/svg-to-pdf/

但在另一台服务器上,我收到此错误:

org.apache.batik.transcoder.TranscoderException: Error while setting up PDFDocumentGraphics2D
Enclosed Exception:
Error while setting up fonts
    at org.apache.fop.svg.PDFTranscoder.transcode(PDFTranscoder.java:189)
    at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
    at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
    at org.apache.batik.apps.rasterizer.SVGConverter.transcode(Unknown Source)
    at org.apache.batik.apps.rasterizer.SVGConverter.execute(Unknown Source)

我一直在谷歌搜索和搜索几个小时,但无济于事。我能做些什么?

我尝试安装以下软件包,但它们没有帮助:

sudo apt-get install gsfonts gsfonts-x11 gsfonts-other batik \
    libbatik-java libxmlgraphics-commons-java  \
    libxmlgraphics-commons-java fop sun-java6-fonts

我的情况是:

  • Debian 6.0.3
  • Sun Java 版本“1.6.0_26”
  • JAR:avalon-framework-4.2.0.jar batik-all-1.7.jar commons-io-1.3.1.jar commons-logging-1.0.4.jar fop-0.95.jar log4j-1.2.15.jar xml- apis-ext.jar xmlgraphics-commons-1.3.1.jar
4

2 回答 2

3

Sincerely it is not a good idea to create such temporary files inside the jetty structure from the Debian package. In case of an update, you may get into troubles. Such a cache directory should be located in /var, like /var/tmp for instance.

根据文档,FOP 应该在失败的情况下使用临时目录。可能你的发现值得一个错误报告。

在它修复之前,您应该设置cache-file选项 禁用缓存use-cache是另一种方式,但可能会影响性能。

于 2012-03-02T23:25:30.863 回答
2

解决这个问题的方法是log4j.properties我把级别调高到TRACE.

在那里,我看到了之前看到的额外日志TranscoderException

2012-02-28 11:51:24,863 DEBUG: org.apache.fop.fonts.FontCache: 
   Writing font cache to /usr/share/jetty/.fop/fop-fonts.cache
org.apache.batik.transcoder.TranscoderException: 
   Error while setting up PDFDocumentGraphics2D

Horray for logs! (And writing a log about what the program is about to do, not just once it has done it, so that if the operation fails, then you know what it was trying to do while it failed.)

On Debian, the Jetty webserver runs under the user jetty and has its home directory at /usr/share/jetty/. However, the jetty user does not have write-access to its own home directory, therefore this ~/.fop directory could not be created.

adrian@10770-02:~$ grep jetty /etc/passwd
jetty:x:107:111::/usr/share/jetty:/bin/false
adrian@10770-02:~$ ls -ld /usr/share/jetty
drwxr-xr-x 7 root root 4096 Feb 28 11:52 /usr/share/jetty/

I don't know whether this is by design, or a bug, but creating this directory so that Jetty could write it...

sudo mkdir -p -m 0777 /usr/share/jetty/.fop

...solved the problem.

于 2012-02-28T11:00:25.673 回答