Skip to Content
avatar image
-1
Former Member

Converting HTML to PDF in ABAP

Hello,

I have requirement of sending pdf document as an attachment in email. But the scenario is not straight forward. I am getting my data in JSON format from the client, I then convert the JSON to XML and apply XSL transformation to convert to HTML.

I now want to convert the HTML to PDF. Is there any way in ABAP to convert the HTML content to PDF content.

Ex: I get my HTML content something like this in ABAP.

data : lv_html type string.

lv_html = '<table> <tr> <td>Column 1</td> <td>Column 2</td> </tr> </table>'.

Regards,

Purayil.

Add comment
10|10000 characters needed characters exceeded

  • I've converted some of the comments to answers. Just so people know what has happened.

  • Former Member

    Hi Purayil,

    Did you solve your issue? Can you please share your solution? Many thanks.

    I tried sending HTML to smartform and generated smartform output from spool into PDF but unfortunately it is in HTML. Smartform print it as html string with tags. I think we need some kind of container to render html and get output from there, but in WebUI we can not use CL_GUI_HTML_VIEWER. Any other idea?

    BR,

    Tauqir

  • Get RSS Feed

6 Answers

  • Best Answer
    Jun 24, 2017 at 06:38 AM

    ABAP systems are not universal converters, they only convert SAP proprietary formats (sapscript, smart forms, ABAP lists). You must use a dedicated software.

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 25, 2017 at 06:50 AM

    I disagree....

    I would get my data into an internal table via a simple transformation. Then I would output a smartform which is a representation of the document I have to send to spool and convert the OTF to PDF - all proven technology.

    Rich

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 25, 2017 at 01:22 PM

    And something more far fetched - donĀ“t know if it is feasible:

    Send HTML via OLE automation to Word and let the desktop application do the conversion.

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 22, 2017 at 11:22 AM

    I had this requirement too some time ago. In my case, I had to combine several html files into one PDF file. To achieve this, I used a 3rd party command line tool named wkhtmltopdf (https://wkhtmltopdf.org , https://github.com/wkhtmltopdf/wkhtmltopdf). To use it, you save the html files to a folder, then run this command line tool with the names of the files and a .pdf file name. Then you read the generated pdf file.

    Since it doesn't need to display anything, it can run in the background. I have created a web service which has html file contents as input (array of string) and pdf content as output (xstring). It runs on Tomcat on a separate server. I call that web service from Abap.

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 26, 2017 at 08:40 AM

    If you have access to GUI you can load html into CL_GUI_HTML_VIEWER then send it to spool and try to convert spool to pdf with CONVERT_ABAPSPOOLJOB_2_PDF.

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 19 at 04:32 PM

    Ran into the same once yet I decided to not to resolve it manually and used the tools found through the github forum and some googling. There are dozens of free tool to convert html to pdf but, as you may suggest, all of them are doing so like a crap and there's no chance you could get away with not to edit it manually. I did so with this editing tool ds11.pdffiller.com because it's the cheapest one I've found back then. Short of features yet it worth it

    Add comment
    10|10000 characters needed characters exceeded