Creating PDF output in Adobe CQ

When you author in Adobe CQ, you may need to create a pdf version of the page. PDF pages would be helpful for users if they need to read the content when they are not connected to Internet.

Adobe CQ allows you to create the pdf version of the page using an OSGi bundle, PDF rewriter. After activating the content, call the page with the .pdf extension in the Author instance. The call will be automatically resolved to provide you with the pdf view of the content.

This blog entry explains how to create a pdf output using Adobe CQ 5.5 QuickStart.

It is assumed that:

  • Author instance is installed on port 4502 on the local machine.
  • Writer instance is installed on port 4503 on the local machine.

Check if PDF Writer bundle is installed and it’s Active in your instance.

  1. Login to Adobe CQ Web Console Configuration.  (http://localhost:4502/system/console/configMgr)
  2. Select OSGi > Bundles.
  3. Filter for Day Communique 5 Rewriter.
  4. Ensure that the bundle is installed and is Active.

Update the XSLT based on your component

While generating a pdf from html, you need to define the XSLT that transforms each element (component) to pdf format. Basically, you need to map all the components to a new style.
By default, Adobe CQ uses the XSLT defined in the following path: /libs/wcm/core/content/pdf/page2fo.xsl
Assume that you use the image component that inherits foundation/components/textimage. And, in the author instance, you have inserted an image using the component. To include the image in the pdf view, add the following in the XSLT.

<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 test="file">
 <fo:block><fo:external-graphic src="sling:/{$resource}/par/{local-name()}/file" content-width="100pt" content-height="100pt"/></fo:block>
 <xsl:if test="@FileRef">
 <fo:block><fo:external-graphic src="sling:/{@FileRef}" content-width="100pt" content-height="100pt"/></fo:block>
 <xsl:if test="image/@fileReference">
 <fo:block><fo:external-graphic src="sling:/{$resource}/par/{local-name()}/image.img.png" content-width="100pt" content-height="100pt"/></fo:block>
 <fo:block font-size="12pt" space-before.optimum="12pt" text-align="start"><xsl:apply-templates select="text"/></fo:block>

Ensure that every component you use in the page has a corresponding XSLT match.

Replicate the XSLT file to the publish instance

This is an important step, since the author instance still has the outdated version of XSLT. You need to activate the XSLT that you updated and make the most updated version available in your author instance.

  1. Login to SiteAdmin. (http://localhost:4502/siteadmin)
  2. Click Tools and in the left navigator select Replication > Activate Tree.
  3. Double-click Activate Tree.
  4. Provide the start path as /libs/wcm/core/content/pdf/page2fo.xsl
  5. Click Dry Run to see the file that is updated after the last Activation.
  6. Select the page2fo.xsl file and click Activate.

Comments are closed.