[英]Image not Found- XSL-FO
盡管我已經設置了正確的圖像路徑,但 XSL-Fo 無法檢索我的圖像。
<fo:external-graphic src="../graphics/bullet.png" content-height="0.5cm" />
每次嘗試通過 Windows 的命令提示符處理文件時,我都會收到此錯誤。
org.apache.fop.events.LoggingEventListener processEvent
SEVERE: Image not found. URI: bullet.png. (See position 26:80)
org.apache.fop.events.LoggingEventListener processEvent
SEVERE: Image not found. URI: bullet.png. (No context info available)
org.apache.fop.events.LoggingEventListener processEvent
源路徑是 APACHE 的 FOP 圖像示例提供的確切格式。 我什至在渲染外部圖形時執行了他們的“image.fo”文件,但仍然遇到上述錯誤(使用不同的圖像文件)。
是否有替代解決方案?
相對 URI 相對於基本 URI ( https://xmlgraphics.apache.org/fop/fo.html#external-resources )。
如果您沒有在 FOP 配置中設置基本 URI,則基本 URI 是當前目錄 ( https://xmlgraphics.apache.org/fop/1.1/configuration.html )。
相對於您運行 FOP 的目錄的圖像文件在哪里?
使用時是否有效:
<fo:external-graphic src="examples/fo/graphics/bullet.png" content-height="0.5cm" />
?
我的外部圖形標簽如下所示:
<fo:external-graphic content-height="15.73mm" src="url('logo.png')"/>
我不得不將 logo.png 文件放在與 xsl 文件相同的目錄中。
也就是說,我的 fop 命令如下所示:
$TOOLS/fop-2.0/fop -d -x -xml xmlfiles/xmlfile.xml -xsl xslfiles/xslfile.xsl -pdf pdffiles/pdffile.pdf
我不得不將 .png 文件放在 xmlfiles 目錄中。
我提出這個問題是因為接受的答案說 URI 是“當前目錄”。
正如 Micheal Potter 在https://stackoverflow.com/a/36521536/12227050 中發現的,路徑是相對於 xml 文件的 URI(如果沒有其他基本路徑配置)。 如果你不能確保xml文件和圖形文件之間的關系,你必須使用一個技巧:
圖像路徑相對於主 xml 輸入文件。 因此,訣竅是一方面將一個准空的虛擬 xml 文件作為靠近圖像的主文件,另一方面從輔助文件中訪問所有數據。
例子:
轉換.bat
注意 data.xml 也是相對於 dummy.xml 解析的,所以它是../data.xml
call %dir%/fop -xml script/dummy.xml -xsl script/small.xsl -pdf small.pdf -param doc3node ../data.xml
數據文件
<?xml version="1.0" encoding="UTF-8"?>
<C attr="Attribute here.">
<d>Hello!</d>
<DDDD>Dadadadam</DDDD>
</C>
腳本/dummy.xml
這個文件可能更空
<?xml version="1.0" encoding="UTF-8"?>
<a><B></B></a>
腳本/標志.gif
[not shown here]
腳本/small.xsl
請注意 logo.gif 與 dummy.xml 相關(兩者都位於同一目錄中)。 主要的技巧是二級xml文件的數據基本上是通過document('../data.xml')//element
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:func="http://exslt.org/functions" extension-element-prefixes="func">
<xsl:param name="doc3node" select="''"/>
<xsl:variable name="d3" select="document($doc3node)" />
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="DIN-A4" page-height="29.7cm" page-width="21cm">
<fo:region-body margin-top="1.5cm" margin-bottom="1.5cm" margin-left="2cm" margin-right="2cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="DIN-A4">
<fo:flow flow-name="xsl-region-body">
<xsl:variable name="doc2node" select="'../data.xml'" />
<xsl:for-each select="document($doc2node)//*">
<xsl:call-template name="ListThemAll" />
</xsl:for-each>
<fo:block><xsl:text>... again ...</xsl:text></fo:block>
<xsl:for-each select="$d3//*">
<xsl:call-template name="ListThemAll" />
</xsl:for-each>
<xsl:call-template name="End"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template name="ListThemAll" match="*">
<fo:block><xsl:text>Element: </xsl:text><xsl:value-of select="name()"/></fo:block>
</xsl:template>
<xsl:template name="End">
<fo:block text-align="center">
<fo:external-graphic src="logo.gif" content-width="2.5cm"/>
</fo:block>
</xsl:template>
</xsl:stylesheet>
生成的pdf文件輸出
Element: C
Element: d
Element: DDDD
... again ...
Element: C
Element: d
Element: DDDD
[Centered image]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.