Expand my Community achievements bar.

SOLVED

Converting content page into PDF and save it into DAM

Avatar

Level 1

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

3 Replies

Avatar

Level 1

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.

Avatar

Correct answer by
Community Advisor

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