From Passion to Profession
  • Home
  • Notes
  • Projects
  • Resources
    • Discovery Log
    • Books I Read
    • Blogs I Visit
    • Tools I Use
  • Home
  • Notes
  • Projects
  • Resources
    • Discovery Log
    • Books I Read
    • Blogs I Visit
    • Tools I Use

Adobe CQ Prepends Front Header Image to Pages with .pdf Extension

7/25/2013

0 Comments

 
In this post, I'll show you how to render PDF documentation (.pdf) with an extra image page prepended to the front of the whole PDF document, and how to embed an extra image to the top of an existing page.

According to a previous post - Adobe CQ Renders Pages with Custom Extension - making .pdf an accetable extention can be done in CQ. In fact, by default, the .pdf extension is already accetable by CQ, according to an existing Page.pdf.jsp file at
/libs/foundation/components/primary/cq/Page/Page.pdf.jsp
I'm using CQ5.6.1 which is not too reliable when I played with extension so after try and error, I modified the above file to reference proxy.jsp using full path and without carriage return at the end of line to avoid any possible 500 Internal Server Error. The Page.pdf.jsp file now saved have only one line:
<%@include file="/libs/foundation/components/primary/cq/Page/proxy.jsp" %>
as explained in  Adobe CQ Renders Pages with Custom Extension. 

For rendering .pdf, I use the out of the box PDF Rewriter mechanism. CQ5 demonstrates the default PDF Rewriter in their demo sites. For example, you can change an existing URL ends with .html extension:
http://localhost:4502/content/geometrixx-media/en/entertainment/summer-blockbuster-hits-and-misses.html
to .pdf extension to see the default behavior of PDF Rewriter output of a page:
http://localhost:4502/content/geometrixx-media/en/entertainment/summer-blockbuster-hits-and-misses.pdf
If you're lucky, your browser should show you a pdf output generated by a default PDF Rewriter (an XSL-FO file named page2fo.xsl located at /libs/wcm/core/content/pdf/page2fo.xsl by default). If not, you need to configure (see references) and modify the PDF rewriter.

In the sample XSL-FO file, the following lines in red are keys to prepend a front cover image page, and embed a header image banner to a page. The final output is a 2 pages PDF documentation: 
<?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">

    <fo:layout-master-set>
     <fo:simple-page-master master-name="page"
                  page-height="29.7cm"
                  page-width="21.6cm"
                  margin-bottom="2cm">
       <fo:region-body margin-top="0cm"/>
       <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 src="sling://content/dam/public/pdf/frontCoverLATL.jpg/jcr:content/renditions/original"/>


    <fo:page-sequence master-reference="all">
      <fo:static-content flow-name="xsl-region-before">
        <fo:block text-align="end">

        </fo:block>
      </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>
   </fo:root>
  </xsl:template>


  <xsl:template match="*[contains(@sling:resourceType,'company/components/articleHeading')]">
    <xsl:if test="@text">
      
<fo:block>
        <fo:external-graphic src="url('sling://content/dam/public/pdf/frontCoverLATL.jpg/jcr:content/renditions/original'
)" content-type="content-type:image/jpeg"/>
      </fo:block>
      <fo:block font-size="18pt" space-before.optimum="12pt" text-align="start"
        margin-top="1cm"
                margin-left="2.5cm"
                margin-right="2.5cm">
          <xsl:value-of select="@text"/>
      </fo:block>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>

Here's the brief explanation for each snippet in red ...

Tell page2fo.xsl the 'fox' namespace is legit so it'll recognize <fox:external-document>:

xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"
Include in an external image as a separate page in the front of the final PDF document. This image will be a separate pdf page before all other page sequence:
<fox:external-document src="sling://content/dam/public/pdf/frontCoverLATL.jpg/jcr:content/renditions/original"/>
Embed an external image as part of the page (block) in a page of the final PDF document before some other text:
<fo:block>
        <fo:external-graphic src="url('sling://content/dam/public/pdf/frontCoverLATL.jpg/jcr:content/renditions/original')" content-type="content-type:image/jpeg"/>

      
</fo:block>

what to read next

  • Adobe CQ Renders Pages with Custom Extension

references

  • ​XSL-FO Introduction and Resources
  • Creating PDF output in Adobe CQ
  • How can I configure the PDF rewriter?
  • Embed PDFs using PDF Rewriter (page2fo.xsl)


0 Comments



Leave a Reply.

    Categories

    All
    Algorithm
    Concurrency
    CQ
    Data Structure
    Design Pattern
    Developer Tool
    Dynamic Programming
    Entrepreneur
    Functional Programming
    IDE
    Java
    JMX
    Marketing
    Marklogic
    Memory
    OSGI
    Performance
    Product
    Product Management
    Security
    Services
    Sling
    Social Media Programming
    Software Development

    Feed Widget

    Archives

    May 2020
    March 2020
    April 2018
    March 2018
    February 2018
    December 2017
    March 2017
    November 2016
    June 2016
    May 2016
    April 2016
    October 2015
    September 2015
    August 2015
    September 2014
    July 2014
    June 2014
    May 2014
    March 2014
    January 2014
    December 2013
    November 2013
    October 2013
    September 2013
    August 2013
    July 2013
    June 2013

    RSS Feed

in loving memory of my mother  and my 4th aunt
Photos from net_efekt, schani, visnup, Dan Zen, gadl, bobbigmac, Susana López-Urrutia, jwalsh, Philippe Put, michael pollak, oskay, Creative Tools, Violentz, Kyknoord, mobilyazilar