Expand my Community achievements bar.

SOLVED

Convert AEM page to PDF

Avatar

Level 5

Hi all,

I want to convert AEM html page to Pdf (using AEM 6.4)  and a link will be provided to users for to download that Pdf.

I have gone through forum already and found sources which I don't want to use like PDF generator (need licence Adobe Acrobat)  , PDFbox API (some restriction with JavaScript on the page)  and iTextpdf (need to expose code which I can't).

Could anyone share approach what else could be used (best if that is free).

Thanks in advance

Sharma

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

As sachinarora​ suggested, you can go with above option if you don't want user to save pdf via print option then you can use Java API e.g. GitHub - wooio/htmltopdf-java: An HTML to PDF conversion library written in Java, based on wkhtmltop...

You may create a generic servlet with selector says "pdf", and can create download link like mysite/my/page.pdf.html.

Whenever this servlet will be called himl page will be converted into pdf using java API and pdf can be serve as pdf in browser or as a attachment.



Arun Patidar

View solution in original post

6 Replies

Avatar

Community Advisor

I have an approach which might work.You have to do 2 things in it.

1. As you have mentioned a link will be provided to users, you can add a query parameter in URLs of a page like /home.html?print=page. In Javascript you can give a condition to run window.print() in case print == page.It will automatically pop up a window for user to save it as PDF or print page.

2. Add media rule in CSS for print to control content that needs to be added in PDF. Reference URL

Avatar

Correct answer by
Community Advisor

Hi,

As sachinarora​ suggested, you can go with above option if you don't want user to save pdf via print option then you can use Java API e.g. GitHub - wooio/htmltopdf-java: An HTML to PDF conversion library written in Java, based on wkhtmltop...

You may create a generic servlet with selector says "pdf", and can create download link like mysite/my/page.pdf.html.

Whenever this servlet will be called himl page will be converted into pdf using java API and pdf can be serve as pdf in browser or as a attachment.



Arun Patidar

Avatar

Level 1

Hello,

I'm also having this issue and followed the documentation provided however the Core bundle for my project will not start with the following error:

14.02.2020 15:59:55.229 *INFO* [FelixDispatchQueue] org.apache.felix.framework FrameworkEvent PACKAGES REFRESHED
14.02.2020 15:59:58.712 *ERROR* [qtp1371432053-74] org.apache.felix.http.jetty %bundles.pluginTitle: Cannot start (org.osgi.framework.BundleException: Unable to resolve com.aem.company-kds.core [553](R 553.1): missing requirement [com.aem.company-kds.core [553](R 553.1)] osgi.wiring.package; (osgi.wiring.package=io.woo.htmltopdf) Unresolved requirements: [[com.aem.company-kds.core [553](R 553.1)] osgi.wiring.package; (osgi.wiring.package=io.woo.htmltopdf)])
org.osgi.framework.BundleException: Unable to resolve com.aem.company-kds.core [553](R 553.1): missing requirement [com.aem.company-kds.core [553](R 553.1)] osgi.wiring.package; (osgi.wiring.package=io.woo.htmltopdf) Unresolved requirements: [[com.aem.company-kds.core [553](R 553.1)] osgi.wiring.package; (osgi.wiring.package=io.woo.htmltopdf)]

I've tried all versions of the htmltopdf jar with no luck.

Is this still supported?

Thanks in advance for any assistance.

Avatar

Level 1

The only PDF generator on the market today is XpGenerator.  It is offered by my company Xpediant Digital.  It is a full function tool that can:

1.  Create pdf's of individual pages or an entire site

2.  Can automatically generate pdf's for desktop, tablet, and mobile

3.  Can be configured to mimic javascript commands to simulate opening tabs, carousels, and expand accordions

4.  The interface is immediately familiar - as it functions completely within your AEM instance

5.  Gives you flexibility in output - individual page pdf's or complete site files

6.  Custom coversheets to make archiving easy

Let me know if you'd like to take a look or hear more.

Greg McGee - Vice President of Digital Transformation

gmcgee@xpediantsolutions.com

612 845 0860