【发布时间】:2015-01-30 11:40:15
【问题描述】:
我正在尝试使用 xsl-fo 创建一个使用背景图像的 pdf。我设置了相对路径如下:
background-image = "url('../themes/images/logo.gif')"
当我给出像 background-image="C://Images/logo.gif" 这样的绝对路径时,它起作用了。 但是当我使用url在服务器中相对取它时,它就不起作用了。
下面是我的场景。
XML:
<?xml version="1.0" encoding="iso-8859-1"?>
<form-data>
<field>
<name>txtFirstName</name>
<value>ABC</value>
</field>
<field>
<name>txtLastName</name>
<value>XYZ</value>
</field>
</form-data>
XSL-FO(获取 Pdf)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="SPM_Name" page-height="29.7cm" page-width="21cm" margin-top="1.2cm" margin-bottom="1.2cm" margin-left="1.75cm" margin-right="1.75cm">
<fo:region-body margin-top="0.5cm" />
<fo:region-before extent="0.5cm" />
<fo:region-after extent="1cm" />
</fo:simple-page-master>
<fo:page-sequence-master master-name="PSM_Name">
<fo:single-page-master-reference master-reference="SPM_Name" />
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="PSM_Name" initial-page-number="1">
<fo:static-content flow-name="xsl-region-before">
<fo:block text-align="end" font-size="10pt" font-family="serif" line-height="14pt">
Page
<fo:page-number />
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block background-image="url('http://localhost:9081/resources/themes/images/Logo1.gif')" background-position="right" background-color="transparent" >
</fo:block>
<fo:block font-size="20pt" text-align="center" font-family="sans-serif" line-height="20pt" space-after.optimum="15pt" padding-top="18pt">Income Tax Form</fo:block>
<fo:table table-layout="fixed" width="100%" border-collapse="separate">
<fo:table-column column-width="50%" />
<fo:table-column column-width="50%" />
<fo:table-header text-align="center">
<fo:table-row>
<fo:table-cell padding="6pt" border="0.5pt solid black" wrap-option="wrap" keep-together.within-column="always">
<fo:block font-weight="solid">Questions</fo:block>
</fo:table-cell>
<fo:table-cell padding="6pt" border="0.5pt solid black" wrap-option="wrap" keep-together.within-column="always">
<fo:block font-weight="solid">Form Inputs</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body text-align="center">
<fo:table-row>
<fo:table-cell padding="6pt" border="0.5pt solid black" wrap-option="wrap" keep-together.within-column="always">
<fo:block>Your First Name</fo:block>
</fo:table-cell>
<fo:table-cell padding="6pt" border="0.5pt solid black" wrap-option="wrap" keep-together.within-column="always">
<fo:block>
<xsl:value-of select="//field/value[../name/text() = 'txtFirstName']" />
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell padding="6pt" border="0.5pt solid black" wrap-option="wrap" keep-together.within-column="always">
<fo:block>Your Last Name</fo:block>
</fo:table-cell>
<fo:table-cell padding="6pt" border="0.5pt solid black" wrap-option="wrap" keep-together.within-column="always">
<fo:block>
<xsl:value-of select="//field/value[../name/text() = 'txtLastName']" />
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
-
"但是当我使用url在服务器中相对取它时,它不起作用。"相对于什么?
-
在浏览器中打开开发者工具并转到网络选项卡,使用实际路径的“logo.gif”文件的请求应该失败。这应该会给你一个关于请求是在哪里提出的提示(以及你打算去哪里)
-
图像未显示在输出 pdf 中
标签: image pdf xslt relative-path xsl-fo