2 Replies Latest reply on Jun 26, 2013 8:20 PM by Sham HC

    Embed PDFs using PDF Rewriter (page2fo.xsl)

    hk19

      I'm trying to embed an extra PDF file to the front and another PDF to the end based on the default PDF Rewriter (page2fo.xsl) that comes with CQ5 according to,

       

       

      http://forums.adobe.com/thread/918206

      http://cqblueprints.com/xwiki/bin/view/CQ+FAQ/How+can+I+configure+the+PDF+rewriter

      http://xmlgraphics.apache.org/fop/0.95/extensions.html

       

       

      I modified (added) the following lines (in red) in page2fo.xsl to include in extra external pdf docs, expecting to see the the front and the back to be embedded into the PDF output.

       

       

      However, the result is as if those lines were not there. No obvious runtime error. I still see the output of page2fo.xsl without files being merged.

       

       

      What am I doing wrong?

       

      -----------

       

      <?xml version="1.0"?>

      <xsl:stylesheet version="1.0"

        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

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

        xmlns:jcr="http://www.jcp.org/jcr/1.0"

        xmlns:sling="http://sling.apache.org/jcr/sling/1.0"

        xmlns:dam="http://www.day.com/dam/1.0"

        xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">

       

       

        <xsl:param name="resource"/>

       

       

        <xsl:template match="dam:thumbnails"/>

       

       

        <xsl:template match="/">

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

                  xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">

       

          <fo:layout-master-set>

           <fo:simple-page-master master-name="page"

                        page-height="29.7cm"

                        page-width="21cm"

                        margin-top="1cm"

                        margin-bottom="2cm"

                        margin-left="2.5cm"

                        margin-right="2.5cm">

             <fo:region-body margin-top="3cm"/>

             <fo:region-before extent="3cm"/>

             <fo:region-after extent="-3.5cm"/>

           </fo:simple-page-master>

       

       

           <fo:page-sequence-master master-name="all">

             <fo:repeatable-page-master-reference master-reference="page"/>

           </fo:page-sequence-master>

          </fo:layout-master-set>

       

          <fox:external-document content-type="pdf" src="url('sling://content/dam/public/pdf/backCoverLATL.pdf')" />

       

          <fo:page-sequence master-reference="all">

       

            <fo:static-content flow-name="xsl-region-before">

       

              <fo:table  border-collapse="collapse">

                <fo:table-column column-width="50%"/>

                <fo:table-column column-width="50%"/>

                <fo:table-body >

                  <fo:table-row>

                    <fo:table-cell padding="2pt">

                      <fo:block font-size="36pt" space-before.optimum="24pt" text-align="start"><xsl:value-of select="jcr:content/@jcr:title"/></fo:block>

                    </fo:table-cell>

                    <fo:table-cell padding="2pt">

                      <fo:block text-align="end">

                        <fo:external-graphic src="sling://etc/designs/geometrixx/jcr:content/logo/image.jpeg"

                                             content-type="content-type:image/jpeg" width="165px" height="64px"/>

                      </fo:block>

                    </fo:table-cell>

                  </fo:table-row>

                </fo:table-body>

              </fo:table>

            </fo:static-content>

       

            <fo:static-content flow-name="xsl-region-after">

              <fo:block text-align="center" font-size="10pt" font-family="serif" line-height="14pt">Page <fo:page-number/></fo:block>

            </fo:static-content>

       

       

            <xsl:choose>

              <xsl:when test="jcr:content">     

                <fo:flow flow-name="xsl-region-body">

                  <xsl:apply-templates/>

                </fo:flow>

              </xsl:when>

              <xsl:otherwise>

                <fo:flow flow-name="xsl-region-body">

                  <fo:block font-size="18pt" space-before.optimum="12pt" text-align="start"><xsl:value-of select="jcr:content/@jcr:title"/></fo:block>

                </fo:flow>

              </xsl:otherwise>

            </xsl:choose>

          </fo:page-sequence>

       

          <fox:external-document>

             <xsl:attribute name="content-type">pdf</xsl:attribute>

             <xsl:attribute name="src">url('sling://content/dam/public/pdf/backCoverLATL.pdf')</xsl:attribute>

          </fox:external-document>

       

         </fo:root>

        </xsl:template>

       

       

        <xsl:template match="jcr:content">

          <xsl:apply-templates/>

        </xsl:template>

       

       

        <xsl:template match="*[contains(@sling:resourceType,'foundation/components/par')]">

          <xsl:apply-templates/>

        </xsl:template>

       

       

        <xsl:template match="*[contains(@sling:resourceType,'foundation/components/title')]">

          <xsl:if test="@jcr:title">

            <fo:block font-size="18pt" space-before.optimum="12pt" text-align="start"><xsl:value-of select="@jcr:title"/></fo:block>

          </xsl:if>

        </xsl:template>

       

       

        <xsl:template match="*[contains(@sling:resourceType,'geometrixx/components/title')]">

          <xsl:if test="@jcr:title">

            <fo:block font-size="18pt" space-before.optimum="12pt" text-align="start"><xsl:value-of select="@jcr:title"/></fo:block>

          </xsl:if>

        </xsl:template>

       

       

        <xsl:template match="*[contains(@sling:resourceType,'foundation/components/text')]">

          <xsl:if test="@jcr:title">

            <fo:block font-size="18pt" space-before.optimum="12pt" text-align="start"><xsl:value-of select="@jcr:title"/></fo:block>

          </xsl:if>

          <fo:block font-size="12pt" space-before.optimum="12pt" text-align="start"><xsl:apply-templates select="text"/></fo:block>

        </xsl:template>

       

       

        <xsl:template match="*[contains(@sling:resourceType,'geometrixx/components/text')]">

          <xsl:if test="@jcr:title">

            <fo:block font-size="18pt" space-before.optimum="12pt" text-align="start"><xsl:value-of select="@jcr:title"/></fo:block>

          </xsl:if>

          <fo:block font-size="12pt" space-before.optimum="12pt" text-align="start"><xsl:apply-templates select="text"/></fo:block>

        </xsl:template>

       

       

        <xsl:template match="*[contains(@sling:resourceType,'foundation/components/textimage')]">

          <xsl:if test="@jcr:title">

            <fo:block font-size="18pt" space-before.optimum="12pt" text-align="start"><xsl:value-of select="@jcr:title"/></fo:block>

          </xsl:if>

          <xsl:if test="file">

            <fo:block><fo:external-graphic src="sling:/{$resource}/par/{local-name()}/file" content-width="100pt" content-height="100pt"/></fo:block>

          </xsl:if>

          <xsl:if test="@FileRef">

            <fo:block><fo:external-graphic src="sling:/{@FileRef}" content-width="100pt" content-height="100pt"/></fo:block>

          </xsl:if>

          <xsl:if test="@fileReference">

            <fo:block><fo:external-graphic src="sling:/{$resource}/par/{local-name()}.img.png" content-width="100pt" content-height="100pt"/></fo:block>

          </xsl:if>

          <fo:block font-size="12pt" space-before.optimum="12pt" text-align="start"><xsl:apply-templates select="text"/></fo:block>

        </xsl:template>

       

       

        <xsl:template match="*[contains(@sling:resourceType,'foundation/components/image')]">

          <xsl:if test="file">

            <fo:block><fo:external-graphic src="sling:/{$resource}/par/{local-name()}/file" content-width="100pt" content-height="100pt"/></fo:block>

          </xsl:if>

          <xsl:if test="@FileRef">

            <fo:block><fo:external-graphic src="sling:/{@FileRef}" content-width="100pt" content-height="100pt"/></fo:block>

          </xsl:if>

          <xsl:if test="@fileReference">

            <fo:block><fo:external-graphic src="sling:/{$resource}/par/{local-name()}.img.png" content-width="100pt" content-height="100pt"/></fo:block>

          </xsl:if>

        </xsl:template>

       

       

        <xsl:template match="*[contains(@sling:resourceType,'geometrixx/components/textimage')]">

          <xsl:if test="@jcr:title">

            <fo:block font-size="18pt" space-before.optimum="12pt" text-align="start"><xsl:value-of select="@jcr:title"/></fo:block>

          </xsl:if>

          <xsl:if test="file">

            <fo:block><fo:external-graphic src="sling:/{$resource}/par/{local-name()}/file" content-width="100pt" content-height="100pt"/></fo:block>

          </xsl:if>

          <xsl:if test="@FileRef">

            <fo:block><fo:external-graphic src="sling:/{@FileRef}" content-width="100pt" content-height="100pt"/></fo:block>

          </xsl:if>

          <xsl:if test="@fileReference">

            <fo:block><fo:external-graphic src="sling:/{$resource}/par/{local-name()}.img.png" content-width="100pt" content-height="100pt"/></fo:block>

          </xsl:if>

          <fo:block font-size="12pt" space-before.optimum="12pt" text-align="start"><xsl:apply-templates select="text"/></fo:block>

        </xsl:template>

       

       

        <xsl:template match="*[contains(@sling:resourceType,'geometrixx/components/image')]">

          <xsl:if test="file">

            <fo:block><fo:external-graphic src="sling:/{$resource}/par/{local-name()}/file" content-width="100pt" content-height="100pt"/></fo:block>

          </xsl:if>

          <xsl:if test="@FileRef">

            <fo:block><fo:external-graphic src="sling:/{@FileRef}" content-width="100pt" content-height="100pt"/></fo:block>

          </xsl:if>

          <xsl:if test="@fileReference">

            <fo:block><fo:external-graphic src="sling:/{$resource}/par/{local-name()}.img.png" content-width="100pt" content-height="100pt"/></fo:block>

          </xsl:if>

        </xsl:template>

       

       

        <xsl:template match="p">

           <xsl:apply-templates/>

          <fo:inline font-stretch="ultra-condensed">&#160;</fo:inline><fo:block/>

        </xsl:template>

       

       

        <xsl:template match="br">

          <fo:inline font-stretch="ultra-condensed">&#160;</fo:inline><fo:block/>

        </xsl:template>

       

       

        <xsl:template match="colctrl">

          <fo:table  border-collapse="collapse">

            <xsl:apply-templates select="col"/>

            <fo:table-body >

              <xsl:apply-templates select="row"/>

            </fo:table-body>

          </fo:table>

        </xsl:template>

       

       

        <xsl:template match="col">

          <fo:table-column/>

        </xsl:template>

       

       

        <xsl:template match="row">

          <fo:table-row>

            <xsl:apply-templates select="cell"/>

          </fo:table-row>

        </xsl:template>

       

       

        <xsl:template match="cell">

          <fo:table-cell padding="2pt">

            <xsl:apply-templates/>

          </fo:table-cell>

        </xsl:template>

      </xsl:stylesheet>

        • 1. Re: Embed PDFs using PDF Rewriter (page2fo.xsl)
          hk19 Level 1

          Further experiment in my local CQ5.5 instance shows that I can embed an image in a PDF via <fox:external-document>:

           

              <fox:external-document src="sling://etc/designs/geometrixx/jcr:content/logo/image.jpeg"/>

          But if I try to embed another PDF by referencing the exising original PDF file in DAM:

           

              <fox:external-document content-type="pdf" src="sling://content/dam/public/pdf/frontCoverLATL.pdf/jcr:content/renditions/original"/>

          I don't get the result I expected.

          • 2. Re: Embed PDFs using PDF Rewriter (page2fo.xsl)
            Sham HC Level 7

            Hi HK,

             

            The cq uses fop version 0.95 & is a known bug with fop that it only support images and not pdf.   This is documented in url you have provided. Snip of it at [1].   To verify yourself just download fop 0.95 and execute [2] the fo used at [3].   Now replace with image it works.

             

            As a workaround create an image with snap of pdf & refer that image.

             

            [1]    This feature is incomplete. Support for multi-page documents will be added shortly. At the moment, only single-page images will work.

             

            [2]   

            ./fop sample.fo s.pdf

            Jun 26, 2013 11:07:22 PM org.apache.fop.layoutmgr.ExternalDocumentLayoutManager activateLayout

            SEVERE: Error while inspecting image: include.pdf (No ImagePreloader found for include.pdf)

             

             

            [3]

            <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">

                <fo:layout-master-set>

                    <fo:simple-page-master master-name="A4">

                        <fo:region-body/>

                    </fo:simple-page-master>

                </fo:layout-master-set>

                <fo:page-sequence master-reference="A4">

                    <fo:flow flow-name="xsl-region-body">

                        <fo:block-container>

                            <fo:block>Verification sample</fo:block>   

                            <fo:block>

                            </fo:block>

                        </fo:block-container>

                    </fo:flow>

                </fo:page-sequence>

             

                <fox:external-document content-type="pdf" src="include.pdf"/>

            </fo:root>

             

            Thanks,

            Sham