<fo:external-graphic src =“...”>抛出错误

时间:2017-07-07 14:01:11

标签: c# xslt apache-fop

我使用fop 2.1,我需要加载带有绝对路径的外部图形。我试过这个:

    <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

我收到以下错误:

PM org.apache.fop.events.LoggingEventListener processEvent
SEVERE: Invalid property value encountered in src="url(file:/C:/users/.../application/logo.gif)"  .... Invalid URI specified

有什么想法吗?

我还试着把'&#39;喜欢&#34; url(&#39;文件:/ C:/ users /.../ application / logo.gif&#39;)&#34;而在潜水的地方。没有成功......: - (

与其他一些样式表一样,我确实有外部图形,我试过的功能也将标题带入正常流程(=&gt;非静态)。不是真正的标题,但尝试...:

    <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>

但是:如果我把

独立
<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"/> 

我得到同样的愚蠢错误:

.... Invalid URI specified

2 个答案:

答案 0 :(得分:1)

首先,通过使其作为静态FO文件工作来简化问题,独立于XSLT。一旦静态目标FO文件正常工作,您就可以双击回XSLT。

将其视为@rene commented,您必须使用完整的URI语法,这实际上可能需要另一个/进行本地访问。 (想想protocol://host/path协议是'文件',主机在这里是空的,连续产生三个斜杠):

file:///c:/users

如果您仍然遇到此问题,请执行browser walk up the directory tree以确保文件及其祖先目录都存在。

最后,请注意...无效,如果是..的拼写错误,而不是有关省略路径组件的元符号。

答案 1 :(得分:0)

Oups,我知道了!

这是一个愚蠢的Windows斜杠/反斜杠......!

获取图像路径时,我只需要转换斜杠:

<script>
$.noConflict();


  $('.grid-stack').gridstack({
        animate: true,
        auto: true,
        width: 12,
        float: true,
        vertical_margin: 0,
        always_show_resize_handle: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
        resizable: {
            handles: 'e, se, s, sw, w'
        }   
    });

在样式表(xsl)中,您甚至可以在“file:”之后使用单斜杠版本(!):

string logoImg = BackslashToSlash(Path.GetFullPath(imageFile));
xsltArgumentList.Add("logo-image", logoImg);
...

    public static String BackslashToSlash(String inStr)
    {
        try
        {
            return inStr.Replace("\\", "/");
        }
        catch (Exception)
        {
            return "";
        }
    }

尽管如此,我认为它实际上应该是三个斜线:

<fo:external-graphic src="url({concat('file:/',$logo-image)})" />
相关问题