‎2017 Jun 23 4:01 PM
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.
‎2017 Jun 24 7: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.
‎2017 Jun 24 7: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.
‎2017 Jun 25 7: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
‎2017 Jun 25 3:24 PM
I agree, SAP can convert proprietary format OTF (smart forms) to PDF. But not HTML to PDF.
‎2017 Jun 26 9:16 AM
Hi Richard,
I tried this by adding it to internal table and converting to PDF via FM CONVERT_OTF. As Sandra said, it needs to be in an OTF format. The function module gave an error BAD_OTF because the format is incorrect. It expects the contents to be in a particular format in the table OTF with TDPRINTCOM and TDPRINTPAR.
@Sandra, thanks for your reply. I should be looking to do it in Java and call this from ABAP.
Regards,
Purayil.
‎2017 Jun 26 9:22 AM
True, however, I was proposing an alternative solution. So my disagreement was not in the fact that you can't convert HTML but in the implication that you can't do it full stop....
Rich
‎2017 Jun 26 9:24 AM
You're missing the smartform output:
"Then I would output a smartform which is a representation of the document"
That is where the OTF conversion comes in.
"I should be looking to do it in Java and call this from ABAP."
Nope - that just really complicates things and is not needed.
‎2017 Jun 26 10:58 AM
Hello Richard,
Thanks for your response, My HTML is dynamic, ABAP does not have any idea of the HTML content.
I don't have much knowledge on smartfomrs, if I am correct the smartfom should have a template which if kind of fixed.
Correct me if I am wrong.
Regards,
Purayil.
‎2017 Jun 26 11:20 AM
Hi.
Is your html a fixed message with variable parts ? If so then a smartforms can handle that easily. If it is totally dynamic then parse the html, output it to a standard text and use that text in the smartform. Smartforms are very dynamic.
Rich
‎2017 Jun 28 9:00 AM
Hello Richard,
My HTML is completely dynamic, I have tables, radio buttons, list items etc. and also with CSS. How do you mean to parse it to standard text?
Purayil.
‎2017 Jun 28 9:19 AM
You can create and read standard texts on the fly using function modules SAVE_TEXT and READ_TEXT. You say it is completely dynamic - Surely it must conform to some sort of structure ?
‎2017 Jun 25 2: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.
‎2017 Jun 26 9: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.
‎2017 Jun 27 7:54 AM
‎2017 Jun 26 9:41 AM
I've converted some of the comments to answers. Just so people know what has happened.
‎2017 Nov 10 8:28 AM
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
‎2017 Nov 22 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.
‎2018 Jul 19 5: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
‎2025 Feb 13 9:11 PM
Hi Purayil,
ABAP doesn’t offer a built-in way to convert arbitrary HTML to PDF—it mainly supports conversion for SAP-specific formats like Smart Forms, SAPscript, or ALV lists. For your case, where you're working with dynamic HTML, you'll need to use an external solution.
One option is to use a dedicated HTML-to-PDF conversion API, such as PDFBolt. With such an API, you can send your HTML content via an HTTP request and receive a PDF in response, which you can then attach to your email using ABAP’s standard emailing functions (e.g., BCS).
Alternatively, if your environment allows, you might set up a command-line tool on your server that performs the conversion, and then call that tool from ABAP.
Hope this helps!