这是我的第一个问题,我希望我做得对.抱歉我的英语不好提前:)
我正在使用JSF 2.0(Eclipse IDE),我正在尝试使用Apache FOP 1.0生成一些PDF文件.
我能够使用Apache Fop站点上的说明制作简单的PDF文件,但我无法从我的应用程序文件夹中插入任何图像.我的文件夹结构是这样的:在我的应用程序WebContent中我有(除此之外)pdf_transform/xslt/transformFile.xsl和pdf_transform/xslt/logo.jpg
在transformFile.xsl我有
<fo:block><fo:external-graphic src="url('logo.jpg')"/></fo:block>
Run Code Online (Sandbox Code Playgroud)
但是当我在我的servlet中clik'showPDF'按钮时,我得到没有图像的PDF文件(其他一切都在那里),并在控制台中显示以下消息:
严重:从URI解析返回的Source不包含URI的InputStream:logo.jpg 2010年11月18日下午5:16:49 org.apache.fop.events.LoggingEventListener processEvent SEVERE:找不到图像.URI:logo.jpg.(没有上下文信息)
我尝试使用'logo.jpg'而不是url('logo.jpg'),将图像放在WebContent文件夹内的各个位置并使用不同的导航("./ logo.jpg"),但它没有用.
如果我设置绝对路径(例如"d:/fop/images/logo.jpg"),它工作正常,但我需要在我的应用程序中恢复.
在搜索时,我发现这与fopFactory.setURIResolver()和/或userAgent.setBaseURL()有关.尝试过这个,但没有成功.
我是JSF和FOP的新手,这种形象的情况一直困扰着我.有人可以帮我解决这个问题吗,或者至少指导一下"如何配置相对路径使用FOP"的教程?
编辑:我不希望任何绝对路径和应用程序应独立于其在计算机上的位置工作(可发布).我的搜索告诉我它与配置FOP有关,但我不知道该怎么做:)
提前致谢.
PS这是一种被称为显示PDF的方法:
public void printExchangeRateList(ActionEvent event) {
BufferedOutputStream output = null;
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
String path = externalContext.getRealPath("/");
try {
response.reset();
response.setHeader("Content-Type", "application/pdf");
output = new BufferedOutputStream(response.getOutputStream(), 10240);
File xsltfile = new File(path+"/pdf_transform/xslt/transformFile.xsl");
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
try {
Fop fop …Run Code Online (Sandbox Code Playgroud)