Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to Convert HTML String to PDF?

7,344

Hi ,

I have a requirement to convert a HTML string ( which has html tags, texts and base 64 encoded images) into PDF file and attach it to an email using ABAP code.

I tried by
1. feeding the HTML string to a smartform and fetched the OTF data and converted into PDF. This didnt work as the smartform text doesnt recognize the HTML tags and the encoded image.
2. creating a spool and then converting to PDF. This failed, because the html is written as text into to spool and hence it also didn't workout.

As i am out of ideas. It would be a great help if someone could help me with some ideas.

Thanks in advance
Rian

Hi ,

I have a requirement to convert a HTML string ( which has html tags, texts and base 64 encoded images) into PDF file and attach it to an email using ABAP code.

I tried by
1. feeding the HTML string to a smartform and fetched the OTF data and converted into PDF. This didnt work as the smartform text doesnt recognize the HTML tags and the encoded image.
2. creating a spool and then converting to PDF. This failed, because the html is written as text into to spool and hence it also didn't workout.

As i am out of ideas. It would be a great help if someone could help me with some ideas.

Thanks in advance
Rian

9 REPLIES 9
Read only

Nawanandana
Active Contributor
6,112
Read only

matt
Active Contributor
6,112

There are programs and web services that convert html to pdf. For example htm2pdf.co.uk has an API. I've no connection to this site; it's just the first that came up when I googled.

Buy a license for that, or any other similar, and call it from your ABAP with your html. Get the pdf file in return (as xstring) and attach to your email, using all the BCS stuff.

Or get one of the programs and install on your application server, and create a command that you can run from abap to do the conversion.

Read only

rameez_khan
Active Participant
0 Likes
6,112

This has already been discussed over here and the question has been answered. Some of the possible solutions were discussed and one of them already suggested by Matthew above.

Read only

0 Likes
6,112

Hi Rameez,

Thanks for providing the reference link.
But as i mentioned i was trying to find a solution using just the Abap code without using any third party tools.
But thanks for sharing the link, it looks interesting.

Read only

matt
Active Contributor
6,112

Well, HTML is an open format and PDF is an open format, so there's nothing to stop you writing a converter.

Read only

Sandra_Rossi
Active Contributor
6,112

Nawanandana Edirisinghe I see no relationship between base64 and the question, can you explain how it can help the OP?

Read only

Nawanandana
Active Contributor
0 Likes
6,112

Hey Sandra Rossi IF Rian getting BASE64 format , it can decode using SSFC_BASE64_DECODE and export to PDF , that will be possibility i thought.

Read only

Sandra_Rossi
Active Contributor
6,112

Nawanandana Edirisinghe images inside the HTML are in base64 (I guess: <img src="data:<mimetype>;base64,<base64>">), but the question is much larger, so the solution is only to use an external tool which is able to convert any HTML code into PDF. No need to rewrite an existing conversion tool into ABAP language, just call this external tool, and it will be able to decode the base64 images and convert them into PDF embedded images.

Read only

DoanManhQuynh
Active Contributor
0 Likes
6,112

you may try using cl_abap_browser to display html file with print button and print from there. copy the demo: DEMO_PICTURE_IN_HTML and try yourself...