问题描述
我使用fop 2.1,并且需要加载具有绝对路径的外部图形.我试过了:
I use fop 2.1 and I need to load an external graphic with an absolute path. I tried this:
<fo:root xsl:use-attribute-sets="text-attributes">
<fo:layout-master-set>
...
<fo:page-sequence master-reference="master">
<xsl:call-template name="pageHeader"/>
<xsl:call-template name="pageFooter"/>
<fo:flow flow-name="xsl-region-body">
...
</fo:flow>
</fo:page-sequence>
...
<xsl:template name="pageHeader">
<fo:static-content flow-name="region-before-first">
<fo:block>
<fo:external-graphic src="url({concat('file:/',$logo-image)})" height="15mm" content-height="15mm"/>
</fo:block>
</fo:static-content>
</xsl:template>
$ logo-image包含绝对路径,例如C:/users/.../application/logo.gif
$logo-image contains the absolute path like C:/users/.../application/logo.gif
我收到以下错误:
PM org.apache.fop.events.LoggingEventListener processEvent
SEVERE: Invalid property value encountered in src="url(file:/C:/users/.../application/logo.gif)" .... Invalid URI specified
有什么主意吗?
我还尝试将'像"url('file:/C:/users/.../application/logo.gif')"放在其他地方,否则放在潜水员的地方.没有成功...:-(
I tried also to put ' around like "url('file:/C:/users/.../application/logo.gif')" and else at divers place. No success... :-(
就像在其他样式表中一样,我确实具有外部图形,该图形我尝试过的功能也将标题带入正常流程(=>不是static).不是标题的真正方法,而是尝试...:
As in some other stylesheets I do have external graphic that functions I tried also take the header into the normal flow ( => not static ). Not really the way to do for a header, but a try... :
<fo:root xsl:use-attribute-sets="text-attributes">
<fo:layout-master-set>
...
<fo:page-sequence master-reference="master">
<!--<xsl:call-template name="pageHeader"/>-->
<xsl:call-template name="pageFooter"/>
<fo:flow flow-name="xsl-region-body">
<xsl:call-template name="pageHeader"/>
...
</fo:flow>
</fo:page-sequence>
...
<xsl:template name="pageHeader">
<fo:block-container position="absolute" top="10mm" left="10mm">
<fo:block>
<fo:external-graphic src="url({concat('file:/',$logo-image)})" height="15mm" content-height="15mm"/>
</fo:block>
</fo:block-container>
</xsl:template>
但是:如果我放了,则独立
But: Independantly if I put
<fo:external-graphic src="url({concat('file:/',$logo-image)})" height="15mm" content-height="15mm"/>
或
<fo:external-graphic src="url({concat('file:///',$logo-image)})" height="15mm" content-height="15mm"/>
我得到同样的愚蠢错误:
I get same stupid error:
.... Invalid URI specified
推荐答案
首先,通过使其独立于XSLT用作静态FO文件来简化事务.工作了静态目标FO文件后,您就可以再次回到XSLT.
First, simplify matters by getting it to work as a static FO file, independent of XSLT. You can double-back to the XSLT once you have a static target FO file working.
意识到作为 @rene评论,您必须使用完整的URI语法,实际上可能还需要另一个/
进行本地访问. (请考虑protocol://host/path
,其中协议是'文件',并且主机在此处为空,连续产生三个斜杠):
Realize that as @rene commented, you have to use full URI syntax, which may actually require yet another /
for local access. (Think protocol://host/path
where protocol is 'file' and host is empty here, yielding three slashes in a row):
file:///c:/users
如果您对此仍有疑问,请执行 浏览器浏览目录树 ,以确保文件及其祖先目录都存在.
If you still have trouble with this, do a browser walk up the directory tree to make sure that the files and its ancestor directories all exist.
最后,请注意,...
无效,以防万一,这是..
的错别字,而不是有关省略路径组件的元符号.
Finally, note that ...
isn't valid, in case that's a typo for ..
and not a meta-notation about elided path components.
这篇关于< fo:external-graphic src = ...>引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!