XSL-FO - 将背景图像添加到多个 PDF 页面
XSL-FO - add a background image to multiple PDF pages
我正在通过 Apache FOP、java 库使用 XML 和 XSL 生成 pdf。
我不知道如何为每个页面(甚至单个页面...)显示背景图片。
背景需要放在正文的底部,几乎覆盖整个页面(不包括边距)。
我已经搜索过了,没有好的结果,先谢谢了。
<?xml version="1.0" encoding="windows-1252" ?>
<xsl:stylesheet version="2.0" exclude-result-prefixes="fo"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="TbOnoriCaricaVO">
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="template"
page-height="297mm" page-width="210mm" margin-
top="33mm"
margin-bottom="36mm" margin-left="22mm" margin-
right="25mm">
<fo:region-body>
<fo:block width="15mm" height="25mm">
<fo:external-graphic src="file:///D:/LungaNavigazioneAerea.png" />
</fo:block>
</fo:region-body>
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:for-each select="TbOnoriCaricaVORow">
<!--
<fo:block-container absolute-position="absolute"
top="-20mm" left="-30mm" width="15mm" height="25mm"
background-image="file:///D:/LungaNavigazioneAerea.png">-->
<xsl:variable name="medal">
<xsl:value-of select="OnoriDesOnor"/>
</xsl:variable>
<fo:page-sequence master-reference="template">
<fo:flow flow-name="xsl-region-body">
<fo:block-container absolute-position="absolute"
top="-20mm" left="-30mm" width="15mm" height="25mm"
background-image="D:/LungaNavigazioneAerea.png">
<fo:block/>
</fo:block-container>
<fo:block font-family="Times New Roman" font-size="13pt" margin-top="0.43cm" margin-
left="1.7cm">
<fo:inline>
<xsl:value-of select="normalize-space(concat("Numero d'ordine: ",
"~~~~~/", OnoriFfaa))"/>
</fo:inline>
</fo:block>
<fo:block text-align="center" margin-top="1.04cm">
<fo:inline font-family="Times New Roman" font-size="19pt">
~~~~~~~~~~~~~~~~~
</fo:inline>
</fo:block>
<fo:block text-align="center" font-family="Times New Roman" font-size="13pt" margin-
top="-0.04cm">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
</fo:block>
<fo:block text-align="center" font-family="Times New Roman" font-size="13pt" margin-
top="0.14cm">
~~~~~~~~
</fo:block>
<fo:block text-align="left" font-family="Times New Roman" font-size="12pt" margin-
top="5.31cm" margin-left="1.7cm">
<fo:inline>
<xsl:value-of select="normalize-space(concat('Al ~~~~~~~ ~~~~~~~~~~ ', OnoriNome,
' ', OnoriCognome))"/>
</fo:inline>
</fo:block>
<fo:block text-align="left" font-family="Times New Roman" font-size="12pt" margin-
left="1.7cm">
<fo:inline>
<xsl:value-of select="normalize-space(concat('nato a ', OnoriLuogoNas, ' il ',
bornDate))"/>
</fo:inline>
</fo:block>
<fo:block text-align="left" margin-top="0.98cm" font-family="Times New Roman" margin-
left="1.7cm">
<fo:inline font-style="Times New Roman" font-size="14pt">
~ ~~~~~~~~ ~~
</fo:inline>
</fo:block>
<fo:block text-align="center" font-size="19pt" font-family="Times New Roman" margin-
top="0.96cm">
~~~~~~~~ ~~~~~~
</fo:block>
<fo:block text-align="center" font-size="19pt" font-family="Times New Roman" margin-
top="0.45cm">
~~~~~~~~~
</fo:block>
<fo:block text-align="center" font-size="19pt" font-family="Times New Roman" margin-
top="0.4cm">
<fo:inline>
<xsl:value-of select="normalize-space(concat('DI ', translate(OnoriTipOnor,
$lowercase, $uppercase)))"/>
</fo:inline>
</fo:block>
<fo:block text-align="left" font-size="12pt" font-family="Times New Roman" margin-
top="1.19cm" margin-left="1.7cm">
~~ ~~~
</fo:block>
<fo:list-block provisional-label-separation="20pt" margin-left="1.8cm" margin-
top="1.16cm">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block font-size="14pt" font-family="italic">
<fo:inline font-style="italic">
~~~~,
</fo:inline>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block font-family="Times New Roman" font-size="14pt" margin-left="0.5cm">
<fo:inline font-family="Times New Roman">
<xsl:value-of select="normalize-space(concat(' ', currentDate))"/>
</fo:inline>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
<fo:block text-align="center" font-size="13pt" font-family="Times New Roman" margin-
top="0.76cm" margin-left="7.58cm">
<fo:inline>
IL CAPO REPARTO
</fo:inline>
</fo:block>
<fo:block text-align="center" font-size="13pt" font-family="Times New Roman" margin-
left="7.58cm">
<fo:inline>
<xsl:value-of select="normalize-space(concat('Dirig. Dott.', '~~~~~~ ~~~~~~'))"/>
</fo:inline>
</fo:block>
<!-- </fo:block-container> -->
</fo:flow>
</fo:page-sequence>
</xsl:for-each>
</fo:root>
</xsl:template>
<xsl:template match="italic">
<fo:inline font-weight="italic">
<xsl:apply-templates select="node()"/>
</fo:inline>
</xsl:template>
</xsl:stylesheet>
您可以在 fo:region-body
上指定背景图片。参见 https://www.w3.org/TR/xsl11/#fo_region-body, where "7.8 Common Border, Padding, and Background Properties" (https://www.w3.org/TR/xsl11/#common-border-padding-and-background-properties) includes background-image
(https://www.w3.org/TR/xsl11/#background-image)。
我正在通过 Apache FOP、java 库使用 XML 和 XSL 生成 pdf。
我不知道如何为每个页面(甚至单个页面...)显示背景图片。
背景需要放在正文的底部,几乎覆盖整个页面(不包括边距)。
我已经搜索过了,没有好的结果,先谢谢了。
<?xml version="1.0" encoding="windows-1252" ?>
<xsl:stylesheet version="2.0" exclude-result-prefixes="fo"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="TbOnoriCaricaVO">
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="template"
page-height="297mm" page-width="210mm" margin-
top="33mm"
margin-bottom="36mm" margin-left="22mm" margin-
right="25mm">
<fo:region-body>
<fo:block width="15mm" height="25mm">
<fo:external-graphic src="file:///D:/LungaNavigazioneAerea.png" />
</fo:block>
</fo:region-body>
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:for-each select="TbOnoriCaricaVORow">
<!--
<fo:block-container absolute-position="absolute"
top="-20mm" left="-30mm" width="15mm" height="25mm"
background-image="file:///D:/LungaNavigazioneAerea.png">-->
<xsl:variable name="medal">
<xsl:value-of select="OnoriDesOnor"/>
</xsl:variable>
<fo:page-sequence master-reference="template">
<fo:flow flow-name="xsl-region-body">
<fo:block-container absolute-position="absolute"
top="-20mm" left="-30mm" width="15mm" height="25mm"
background-image="D:/LungaNavigazioneAerea.png">
<fo:block/>
</fo:block-container>
<fo:block font-family="Times New Roman" font-size="13pt" margin-top="0.43cm" margin-
left="1.7cm">
<fo:inline>
<xsl:value-of select="normalize-space(concat("Numero d'ordine: ",
"~~~~~/", OnoriFfaa))"/>
</fo:inline>
</fo:block>
<fo:block text-align="center" margin-top="1.04cm">
<fo:inline font-family="Times New Roman" font-size="19pt">
~~~~~~~~~~~~~~~~~
</fo:inline>
</fo:block>
<fo:block text-align="center" font-family="Times New Roman" font-size="13pt" margin-
top="-0.04cm">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
</fo:block>
<fo:block text-align="center" font-family="Times New Roman" font-size="13pt" margin-
top="0.14cm">
~~~~~~~~
</fo:block>
<fo:block text-align="left" font-family="Times New Roman" font-size="12pt" margin-
top="5.31cm" margin-left="1.7cm">
<fo:inline>
<xsl:value-of select="normalize-space(concat('Al ~~~~~~~ ~~~~~~~~~~ ', OnoriNome,
' ', OnoriCognome))"/>
</fo:inline>
</fo:block>
<fo:block text-align="left" font-family="Times New Roman" font-size="12pt" margin-
left="1.7cm">
<fo:inline>
<xsl:value-of select="normalize-space(concat('nato a ', OnoriLuogoNas, ' il ',
bornDate))"/>
</fo:inline>
</fo:block>
<fo:block text-align="left" margin-top="0.98cm" font-family="Times New Roman" margin-
left="1.7cm">
<fo:inline font-style="Times New Roman" font-size="14pt">
~ ~~~~~~~~ ~~
</fo:inline>
</fo:block>
<fo:block text-align="center" font-size="19pt" font-family="Times New Roman" margin-
top="0.96cm">
~~~~~~~~ ~~~~~~
</fo:block>
<fo:block text-align="center" font-size="19pt" font-family="Times New Roman" margin-
top="0.45cm">
~~~~~~~~~
</fo:block>
<fo:block text-align="center" font-size="19pt" font-family="Times New Roman" margin-
top="0.4cm">
<fo:inline>
<xsl:value-of select="normalize-space(concat('DI ', translate(OnoriTipOnor,
$lowercase, $uppercase)))"/>
</fo:inline>
</fo:block>
<fo:block text-align="left" font-size="12pt" font-family="Times New Roman" margin-
top="1.19cm" margin-left="1.7cm">
~~ ~~~
</fo:block>
<fo:list-block provisional-label-separation="20pt" margin-left="1.8cm" margin-
top="1.16cm">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block font-size="14pt" font-family="italic">
<fo:inline font-style="italic">
~~~~,
</fo:inline>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block font-family="Times New Roman" font-size="14pt" margin-left="0.5cm">
<fo:inline font-family="Times New Roman">
<xsl:value-of select="normalize-space(concat(' ', currentDate))"/>
</fo:inline>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
<fo:block text-align="center" font-size="13pt" font-family="Times New Roman" margin-
top="0.76cm" margin-left="7.58cm">
<fo:inline>
IL CAPO REPARTO
</fo:inline>
</fo:block>
<fo:block text-align="center" font-size="13pt" font-family="Times New Roman" margin-
left="7.58cm">
<fo:inline>
<xsl:value-of select="normalize-space(concat('Dirig. Dott.', '~~~~~~ ~~~~~~'))"/>
</fo:inline>
</fo:block>
<!-- </fo:block-container> -->
</fo:flow>
</fo:page-sequence>
</xsl:for-each>
</fo:root>
</xsl:template>
<xsl:template match="italic">
<fo:inline font-weight="italic">
<xsl:apply-templates select="node()"/>
</fo:inline>
</xsl:template>
</xsl:stylesheet>
您可以在 fo:region-body
上指定背景图片。参见 https://www.w3.org/TR/xsl11/#fo_region-body, where "7.8 Common Border, Padding, and Background Properties" (https://www.w3.org/TR/xsl11/#common-border-padding-and-background-properties) includes background-image
(https://www.w3.org/TR/xsl11/#background-image)。