我有一些问题需要在我的PDF中显示外部图形.我尝试使用各种路径,url()但似乎没有任何工作.这是我缺少的东西吗?
<fo:table-cell>
<fo:block>
<fo:external-graphic src="url(ss/naam.png)"></fo:external-graphic>
</fo:block>
</fo:table-cell>
Run Code Online (Sandbox Code Playgroud)
我正在使用Apache FOP 1.1 Ver.
首先你应该告诉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);
Run Code Online (Sandbox Code Playgroud)
在您的XSL模板文件中
<fo:table-cell>
<fo:block>
<fo:external-graphic src="url(resources/naam.png)"></fo:external-graphic>
</fo:block>
</fo:table-cell>
Run Code Online (Sandbox Code Playgroud)
这里naam.png将在resources /目录中
我在项目的资源主管中添加了所有图像和所需的字体字体文件.它对我来说很好.谢谢