java - 外部图形相对路径
问题描述
如何将 fo:external-graphic 与相对路径一起使用?
我一直在到处寻找,但找不到答案。大多数答案都谈到将图像放入我的 Java 项目的资源中,但这对我来说不起作用,因为它是生成运行时的图像。
所以简而言之..我可以将某种变量放入我的 XSL 文档中,然后通过回调在我的 java 代码中设置它吗?
<fo:table-cell>
<fo:block margin-top="23mm">
<fo:external-graphic src="url({$ImagePath}CAPTION.PNG)" height="17mm"
content-height="scale-to-fit" content-width="65mm"
scaling="non-uniform"/>
</fo:block>
</fo:table-cell>
解决方案
我找到了解决方案!参数!
首先,在您的 XSL 文档中,您必须定义您的变量:
然后稍后您可以使用它:
<fo:table-cell>
<fo:block margin-top="23mm">
<fo:external-graphic src="url({$ImagePath}CAPTION.PNG)" height="17mm"
content-height="scale-to-fit" content-width="65mm"
scaling="non-uniform"/>
</fo:block>
</fo:table-cell>
在呈现您的文档之前,您已经在 JAVA 代码中设置了变量:
// 设置 XSLT TransformerFactory factory = TransformerFactory.newInstance(); 变压器变压器 = factory.newTransformer(new StreamSource(xsltFile));
// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
transformer.setParameter("ImagePath", "C:/Temp/Poland/");
transformer.transform(xmlSource, res);
推荐阅读
- jenkins - 在詹金斯中存储部署路径的最佳方式
- r - 将 df 帧值输入到 GET 函数 Web 查询中
- ansible - ansible 从角色获取结果并附加到列表
- python - 将 javascript 文件夹转换为 python
- sql - SQL Server:日期减去
- python-asyncio - 无法弄清楚如何正确安排我的异步功能
- c# - 无法使用 MySql 连接编译 c# 项目
- swift - 带有滚动过渡样式的 UIPageViewController 中的大标题不会折叠
- c# - EF Core Attach/AttachRange 方法不起作用
- java - spring boot @EnableConfigurationProperties 标记内部类发生异常