lots_of_questions
lots_of_questions

Reputation: 1149

XSLFO overlay image

I'm using ApacheFOP to create a pdf which has multiple pages of content and a watermark (semi-transparent) on every page. I'm struggling quite a bit with XSLFO and got a proof of concept working using the list functionality - however I imagine there is a simpler way. Can someone more familiar with xslfo provide a simpler solution? Below is my code:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

  <xsl:output method="xml" indent="yes" />
  <xsl:param name="watermarkPath" />
  <xsl:param name="pdfPages" />
  <xsl:template match="/">

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

  <fo:layout-master-set>
    <fo:simple-page-master master-name="my-page"
      page-height="11in" page-width="8.5in" margin="0.5in">
      <fo:region-body />
    </fo:simple-page-master>
  </fo:layout-master-set>

  <fo:page-sequence master-reference="my-page">
    <fo:flow flow-name="xsl-region-body">

      <xsl:for-each select="$pdfPages">
        <fo:block-container>
          <fo:list-block>
            <fo:list-item>
              <fo:list-item-label>
                <fo:block>
                  <fo:external-graphic
                    content-width="7.5in">
                    <xsl:attribute name="src">
                    <xsl:value-of
                      select="concat('data:image/png;base64,',.)" />
                  </xsl:attribute>
                  </fo:external-graphic>
                </fo:block>
              </fo:list-item-label>

              <fo:list-item-body start-indent="body-start()">
                <fo:block>
                  <fo:external-graphic
                    content-width="7.5in">
                    <xsl:attribute name="src">
                    <xsl:value-of select="$watermarkPath" />
                  </xsl:attribute>
                  </fo:external-graphic>
                </fo:block>
              </fo:list-item-body>
            </fo:list-item>
          </fo:list-block>
        </fo:block-container>
      </xsl:for-each>

    </fo:flow>
  </fo:page-sequence>
</fo:root>

  </xsl:template>
</xsl:stylesheet>

Upvotes: 0

Views: 5321

Answers (2)

Ronny Weckx
Ronny Weckx

Reputation: 1

I put my background image in the region-body :

fo:region-body background-image="{$Url}"/

Upvotes: -1

Kevin Brown
Kevin Brown

Reputation: 8877

Not sure it works with FOP but if it was a full size image of the page ...

<fo:layout-master-set>
  <fo:simple-page-master master-name="my-page"
    page-height="11in" page-width="8.5in" margin="0.5in">
    <fo:region-body />
    <fo:region-before extent="11in" region-name="myheader" background-image="{path-to-my-image}"/>
  </fo:simple-page-master>
</fo:layout-master-set>

If not, then put an absolute-positioned block-container inside the actual static-content for region "myheader" and don't use the background-image above.

<fo:page-sequence master-reference="my-page">
  <fo:static-content flow-name="myheader">
    <fo:block-container position="absolute" top="XX" left="XX">
       <fo:block>
         <fo:external-graphic .../>
       </fo:block>
     </fo:block-container>
  </fo:static-content>

If you truly want an overlay (meaning over the top of all content) then put it in region-after and not before.

Upvotes: 3

Related Questions