xml - XSL-FO - 将背景图像添加到多个 PDF 页面
问题描述
我正在通过 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,其中“7.8 通用边框、填充和背景属性”(https://www.w3.org/TR/xsl11/#common- border-padding-and-background-properties)包括background-image
(https://www.w3.org/TR/xsl11/#background-image)。
推荐阅读
- ios - Spotify iOS SDK
- javascript - 复选框输入触发 Bootstrap 手风琴折叠事件
- reactjs - 如何实现 react-dnd useDragLayer?
- r - 为什么文本连接不会在管道工 API 运行中持续存在?
- security - 地理定位 WiFi 设备的准确位置
- reporting-services - RDL 报告在导出为 PDF 时显示图像翻转(旋转 180 度)
- reactjs - React 美丽的 DnD- 嵌套列表,但无需在父列表之间拖动
- node.js - 如何处理电子邮件并将其转发到目的地
- javascript - 如何使用浏览器后退按钮关闭覆盖?
- max - Oracle中的最大sql语句