Expand my Community achievements bar.

SOLVED

Custom XML to PDF generation

Avatar

Level 2

Hello,

Here in my project, we have a requirement that involves PDF generation from a specific template. We are considering the OOTB functionality, by configuring our on rewriter (/apps/my_project/config/rewriter). The problem is that the mechanism uses a XML representation from the current node to get XSL-FO and after get the PDF. We need information from other nodes (that in normal HTML we use a WCMUse class to retrieve these information). Let me illustrate:

Node from Page A:

  • path: path_to_page_b
  • someTextField: some_text

Node from Page B:

  • title: page_b_title

In this basic scenario, our PDF from Page A must contain the "some_text" and "page_b_title", but we are not able to access "page_b_title" because it is in another node.

Do you have a clue of how we could achieve this? After some research, I came up with the idea of generating a custom XML (from a Sling Servlet). This way, we could access other nodes using ResourceResolver and then, retrieve all data needed. However, I do not know how to inform the rewriter mechanism to consider my custom XML instead of the default one.

Relevant information:

  • AEM Sites 6.1
  • XSLT 1.0

Thank you in advance.

1 Accepted Solution

Avatar

Correct answer by
Administrator

Hi 

Adding references to what Kunal has mentioned, please have a look at this old community article:- 

Link:- http://blogs.adobe.com/sunil/2013/04/29/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.

Please keep in mind that this approach requires manually writing the XSLT transform file able to process your page (and every component on it) and output the XSL-FO document.

Over-ride its default configuration node at /libs/cq/config/rewriter/pdf with your configuration at /apps/cq/config/rewriter/pdf.

This method ensures that the setting will survive any software upgrades.

P.S. The PDF Writer XSL Stylesheet is at \libs\wcm\core\content\pdf\page2fo.xsl

 

I hope this will be of some help to you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

View solution in original post

4 Replies

Avatar

Employee Advisor

I guess you need to update the transformer class to send new custom parameters(Page B title ) to the XSL script. Check the "Adding Parameters" section in the article linked below- 

http://www.cqblueprints.com/tipsandtricks/pdfrendering.html

Avatar

Level 10

I know there is not a lot of information on this functionality in the AEM docs. I am trackign down information for this use case. 

One option that you do have it to write a custom service that uses a PDF library like PDFBOx. 

Avatar

Correct answer by
Administrator

Hi 

Adding references to what Kunal has mentioned, please have a look at this old community article:- 

Link:- http://blogs.adobe.com/sunil/2013/04/29/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.

Please keep in mind that this approach requires manually writing the XSLT transform file able to process your page (and every component on it) and output the XSL-FO document.

Over-ride its default configuration node at /libs/cq/config/rewriter/pdf with your configuration at /apps/cq/config/rewriter/pdf.

This method ensures that the setting will survive any software upgrades.

P.S. The PDF Writer XSL Stylesheet is at \libs\wcm\core\content\pdf\page2fo.xsl

 

I hope this will be of some help to you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Level 1

Hi,

I am having the same problem.In the link provided above they were telling to  the com.day.cq.rewriter.xml.XSLTTransformer class.Could please someone tell me how I can modify the Transformer class.