为什么我的图像没有显示在 XSL-FO 中?
Why isn't my image displayed in XSL-FO?
在我的一个项目中,我必须使用 xslt 和 xml 在 pdf 中添加图像。但是,我的图片根本不显示。
这是我的 xslt 片段
<fo:block text-align="left">
<fo:external-graphic src="url({$var})" content-height="6pt" content-width="6pt"/>
</fo:block>
(我尝试过使用和不使用 url 部分,但由于它已经存在,我决定在我的问题中展示它)
变量 var 在包含的另一个文件中声明。
<xsl:variable name="imgPath"></xsl:variable>
<xsl:variable name="var">
<xsl:value-of select="$imgPath"/>image.svg</xsl:variable>
我遇到的问题是,虽然我调试的时候可以看到正确的图片路径,但最终结果中并没有显示图片。
我不认为这是图片位置的问题,因为xsl和图片都处于同一级别(所以image.svg是访问图片的正确路径)
通过 XSL-FO 的 SVG 嵌入式图形
Apache FOP Embedded SVG Example
<?xml version="1.0" encoding="utf-8"?>
<!-- external-graphic-SVG-Diagram.fo
- Copyright (c) 2016, HerongYang.com, All Rights Reserved.
-->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="page"
margin="0.1in" page-height="4in" page-width="3in">
<fo:region-body region-name="body" background-color="#eeffff"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="page">
<fo:flow flow-name="body">
<fo:block border-width="1px" border-style="solid">
<fo:block-container width="1in" border-width="1px"
border-style="solid">
<fo:block>1 inch</fo:block>
</fo:block-container>
<fo:block-container width="72px" border-width="1px"
border-style="solid">
<fo:block>72 px</fo:block>
</fo:block-container>
<fo:block-container width="120px" border-width="1px"
border-style="solid">
<fo:block>120 px</fo:block>
</fo:block-container>
<fo:block border-width="1px" border-style="solid">
SVG diagram of 288x288 px at a fixed resolution 144dpi:
<fo:external-graphic src="sample.svg" width="2in" height="2in"
content-width="scale-to-fit" content-height="scale-to-fit"/>
</fo:block>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
RenderX Embedded SVG Example
直接嵌入 XSL-FO 的 SVG:
<fo:block>
Here is the image of a typical roadsign:
<fo:instream-foreign-object content-height="1em">1
<svg:svg xmlns:svg="http://www.w3.org/2000/svg"2
height="100" width="100" viewBox="-50 -50 100 100">
<svg:circle r="50" style="fill:red; stroke:none"/>
<svg:rect x="-40" y="-10" width="80" height="20"
style="fill:white; stroke:none"/>
</svg:svg>
</fo:instream-foreign-object>
</fo:block>
根据 XEP User Guide,fo:instream-foreign-object
可以托管 SVG 图形。
所以,我的问题的答案是我的文件名中有重音符号,这使得我的 FOP 无法找到我的文件。有时最简单的问题最难找到。
在我的一个项目中,我必须使用 xslt 和 xml 在 pdf 中添加图像。但是,我的图片根本不显示。
这是我的 xslt 片段
<fo:block text-align="left">
<fo:external-graphic src="url({$var})" content-height="6pt" content-width="6pt"/>
</fo:block>
(我尝试过使用和不使用 url 部分,但由于它已经存在,我决定在我的问题中展示它)
变量 var 在包含的另一个文件中声明。
<xsl:variable name="imgPath"></xsl:variable>
<xsl:variable name="var">
<xsl:value-of select="$imgPath"/>image.svg</xsl:variable>
我遇到的问题是,虽然我调试的时候可以看到正确的图片路径,但最终结果中并没有显示图片。
我不认为这是图片位置的问题,因为xsl和图片都处于同一级别(所以image.svg是访问图片的正确路径)
通过 XSL-FO 的 SVG 嵌入式图形
Apache FOP Embedded SVG Example
<?xml version="1.0" encoding="utf-8"?>
<!-- external-graphic-SVG-Diagram.fo
- Copyright (c) 2016, HerongYang.com, All Rights Reserved.
-->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="page"
margin="0.1in" page-height="4in" page-width="3in">
<fo:region-body region-name="body" background-color="#eeffff"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="page">
<fo:flow flow-name="body">
<fo:block border-width="1px" border-style="solid">
<fo:block-container width="1in" border-width="1px"
border-style="solid">
<fo:block>1 inch</fo:block>
</fo:block-container>
<fo:block-container width="72px" border-width="1px"
border-style="solid">
<fo:block>72 px</fo:block>
</fo:block-container>
<fo:block-container width="120px" border-width="1px"
border-style="solid">
<fo:block>120 px</fo:block>
</fo:block-container>
<fo:block border-width="1px" border-style="solid">
SVG diagram of 288x288 px at a fixed resolution 144dpi:
<fo:external-graphic src="sample.svg" width="2in" height="2in"
content-width="scale-to-fit" content-height="scale-to-fit"/>
</fo:block>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
RenderX Embedded SVG Example
直接嵌入 XSL-FO 的 SVG:
<fo:block>
Here is the image of a typical roadsign:
<fo:instream-foreign-object content-height="1em">1
<svg:svg xmlns:svg="http://www.w3.org/2000/svg"2
height="100" width="100" viewBox="-50 -50 100 100">
<svg:circle r="50" style="fill:red; stroke:none"/>
<svg:rect x="-40" y="-10" width="80" height="20"
style="fill:white; stroke:none"/>
</svg:svg>
</fo:instream-foreign-object>
</fo:block>
根据 XEP User Guide,fo:instream-foreign-object
可以托管 SVG 图形。
所以,我的问题的答案是我的文件名中有重音符号,这使得我的 FOP 无法找到我的文件。有时最简单的问题最难找到。