Apache FOP:如何设置用于使用相对路径访问外部资源的基本 URL [英] Apache FOP: How to set base URL for accessing external resource using relative path

查看:19
本文介绍了Apache FOP:如何设置用于使用相对路径访问外部资源的基本 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 .xsl 文件中,我使用的是这样的外部图形
<fo:external-graphic width="90pt" height="29pt" src="url(xsl/logo.jpg)"/>

In my .xsl file I am using external graphics like this
<fo:external-graphic width="90pt" height="29pt" src="url(xsl/logo.jpg)"/>

但是生成的 PDF 中没有加载图像,我在控制台中收到此错误.
[ERROR] 创建区域时出错 : Error with image URL: xsl\logo.jpg (系统找不到指定的路径)并且没有指定基本 URL

But image is not getting loaded in the generated PDF and I get this error in console.
[ERROR] Error while creating area : Error with image URL: xsl\logo.jpg (The system cannotfind the path specified) and no base URL is specified

我该如何解决这个问题?我想设置基本 URL 就可以了.但是如何设置基本 URL?请帮忙.

How do I solve this issue? I guess setting the base URL will do. But how to set the base URL? Please help.

推荐答案

我从这个链接得到了一个解决方案
http://groups.yahoo.com/group/XSL-FO/message/6116

I got a solution from this link
http://groups.yahoo.com/group/XSL-FO/message/6116

使用 Java 代码设置基本目录

set base dir using Java code

ServletContext servletContext = getServletConfig().getServletContext();

String appPath = servletContext.getRealPath(""); //root of web app
org.apache.fop.configuration.Configuration.put("baseDir",appPath);

这对我有用.
如果您知道任何更好的解决方案,请发布.

This worked for me.
Please post if you know any better solution.

这篇关于Apache FOP:如何设置用于使用相对路径访问外部资源的基本 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆