Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

GENERATING PDF FROM HTML IN ADOBE EXPERIENCE MANAGER

Avatar

Avatar
Boost 1
Level 1
errsheenah
Level 1

Likes

2 likes

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Applaud 5
View profile

Avatar
Boost 1
Level 1
errsheenah
Level 1

Likes

2 likes

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Applaud 5
View profile
errsheenah
Level 1

26-09-2018


Hi Everyone!

We all have viewed, used or sent PDF files and it is surely one of the most informative and common document formats on the internet.

In this discussion, I would like to share an implementation of generating PDFs from the HTML of a webpage(s) programmatically and easily.

We will make use of two Java libraries: Flying Saucer and iText, along with that to JSOUP – another open-source Java library has been used, for modifying the HTML dynamically.

You can get more information on the Flying Saucer API here.

Here is a brief overview of the implementation :

  • An interface/component with a button, on click of which an AJAX call (using GET method) will be triggered.
  • Path of the page to be converted to PDF will be selected by the author in a dialog which will be sent as a parameter to the servlet.
  • In response we are generating a PDF which opens in a new tab, the user can save it with any name he/she wishes.
  • Requests have been implemented to get all the HTML from the page and the CSS that is being applied on the page.
  • iTextRenderer object is used to set the layout and generate the PDF.
  • To render images MediaReplacedElementfactory is implemented which replaces the image element with iText image element which can be rendered by Flying Saucer API.
  • Utility class using Jsoup has been used to handle all the HTML manipulations i.e removal of certain tags like button, header, and footer of the page.
  • Special CSS has been applied for certain cases to make sure the PDF layout is looking good.

In this blog post, I am going to explain how to implement these steps along with the code required.

Note: Go through this link : GENERATING PDF FROM HTML IN ADOBE EXPERIENCE MANAGER

Replies

Avatar

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,127 likes

Total Posts

6,121 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,127 likes

Total Posts

6,121 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile
kautuk_sahni
Community Manager

26-09-2018

Nice article. Thanks for sharing.

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,260 likes

Total Posts

3,149 posts

Correct Reply

886 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,260 likes

Total Posts

3,149 posts

Correct Reply

886 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

26-09-2018

Thanks for sharing !!!

Avatar

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

440 likes

Total Posts

1,016 posts

Correct Reply

115 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

440 likes

Total Posts

1,016 posts

Correct Reply

115 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile
Veena_Vikram
MVP

26-09-2018

I am going to try this out thanks for sharing. We had some similar requirement lined up for a new requirement

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

26-09-2018

Great community content!

Avatar

Avatar
Level 1
greggd3945325
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
View profile

Avatar
Level 1
greggd3945325
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
View profile
greggd3945325
Level 1

29-11-2018

Will this support or render java script prior to sending to itext?

I have pages with JavaScript and Itext needs us to "use a JavaScript preprocessor to convert the JavaScript into static HTML which can then be fed into" itext.

Gregg

Avatar

Avatar
Validate 1
Level 2
shridhar_sahu
Level 2

Likes

3 likes

Total Posts

36 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 2
shridhar_sahu
Level 2

Likes

3 likes

Total Posts

36 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile
shridhar_sahu
Level 2

17-10-2019

I have a use-case in which i need to generate PDF from HTML page using URL.

I have sample Landing page which accepts a url-encoded parameter id

At the time of page load an ajax call gets triggered and some html gets rendered dynamically through jquery based on that url parameter.

I tried itextpdf7, over here static pdf were getting generated as javascript is not supported.

https://stackoverflow.com/questions/58342600/can-pdfhtml-handle-dynamically-generated-html-content

Can itextpdf & flying saucer handle Javascript(HTML Generated after ajax call) to PDF?

Also,  Can we achieve the use-case using pdf generator without using AEM Forms?

Adobe Experience Manager Help | Converting files using PDF Generator