Converting content page into PDF and save it into DAM | Community
Skip to main content
September 2, 2018
Solved

Converting content page into PDF and save it into DAM

  • September 2, 2018
  • 3 replies
  • 1948 views

I need to convert the content page in a pdf format and save the pdf in dam.

I am able to create pdf file in dam from the below url with a string data but unable to read data from the content page.

Adobe Experience Manager Help | Creating a custom Adobe Experience Manager PDF service

Can anyone suggest me how can i proceed. I am using AEM-6.4

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi,

You can read complete HTML from inputStream and convert into string then create PDF.

Still CSS images are not gonna work with this.

like below:

URL url = new URL("https://www.example.com/");

  URLConnection conn = url.openConnection();

  // open the stream and put it into BufferedReader

  BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

          StringBuilder out = new StringBuilder();

          String line;

          while ((line = reader.readLine()) != null) {

              out.append(line);

          }

          reader.close();

  boolean success = HtmlToPdf.create()

      .object(HtmlToPdfObject.forHtml(out.toString()))

      .convert(pdfFilePath);

3 replies

arunpatidar
Community Advisor
Community Advisor
September 3, 2018
September 3, 2018

Hi Arun,

We have used "https://github.com/wooio/htmltopdf-java". but its giving exception , we have tried with itext also but its not reading the images , can you please tell me  how can i read the image because my html file contains images also.

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
September 3, 2018

Hi,

You can read complete HTML from inputStream and convert into string then create PDF.

Still CSS images are not gonna work with this.

like below:

URL url = new URL("https://www.example.com/");

  URLConnection conn = url.openConnection();

  // open the stream and put it into BufferedReader

  BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

          StringBuilder out = new StringBuilder();

          String line;

          while ((line = reader.readLine()) != null) {

              out.append(line);

          }

          reader.close();

  boolean success = HtmlToPdf.create()

      .object(HtmlToPdfObject.forHtml(out.toString()))

      .convert(pdfFilePath);

Arun Patidar