XSL-FO-将背景图像添加到多个PDF页面中

问题描述 投票:-1回答:1

我正在通过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(&quot;Numero d&apos;ordine: &quot;, 
      &quot;~~~~~/&quot;, 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>
xml xslt background xsl-fo apache-fop
1个回答
0
投票

您可以在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-imagehttps://www.w3.org/TR/xsl11/#background-image)。

© www.soinside.com 2019 - 2024. All rights reserved.