xml XSL-FO 外部图形未显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13267951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XSL-FO external-graphic not showing
提问by Kevin Peters
I'm having some issues getting the external-graphic to show in my PDF. I've tried using all sorts of paths using the url()but nothing seems to work. Is it something else I'm missing?
我在让外部图形显示在我的 PDF 中时遇到了一些问题。我已经尝试过使用各种路径,url()但似乎没有任何效果。我还缺少其他东西吗?
<fo:table-cell>
<fo:block>
<fo:external-graphic src="url(ss/naam.png)"></fo:external-graphic>
</fo:block>
</fo:table-cell>
回答by Oomph Fortuity
I am using Apache FOP 1.1 Ver.
我正在使用 Apache FOP 1.1 版本。
first you should tell apache FOP that where is base path in follwing way. You should copy code as it is.
首先,您应该告诉 apache FOP 以下方式的基本路径在哪里。您应该按原样复制代码。
fopFactory = FopFactory.newInstance();
// for image base URL : images from Resource path of project
String serverPath = request.getSession().getServletContext().getRealPath("/");
fopFactory.setBaseURL(serverPath);
// for fonts base URL : .ttf from Resource path of project
fopFactory.getFontManager().setFontBaseURL(serverPath);
In your XSL template file
在您的 XSL 模板文件中
<fo:table-cell>
<fo:block>
<fo:external-graphic src="url(resources/naam.png)"></fo:external-graphic>
</fo:block>
</fo:table-cell>
Here naam.png will be in resources/ directory
这里 naam.png 将在资源/目录中
I added all images and required font font files in resource director of my project. It is working fine for me. Thank you
我在项目的资源总监中添加了所有图像和所需的字体文件。它对我来说很好。谢谢
回答by Paolo Forgia
回答by Jose Manuel Prieto
Example, it runs in my xls-fo template for Apache FOP.
例如,它在我的 Apache FOP 的 xls-fo 模板中运行。
<fo:external-graphic src='url("src/main/resources/ima/logo.depo.gif")' />
回答by user2157527
<fo:external-graphic src="ss/naam.png"/>
Works for me this way.
这样对我有用。

