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

BASE64 String Image to PDF

former_member213475
Participant
0 Kudos
5,011

Dear Experts,

I need to convert BASE64 string image to PDF content. The converted PDF needs to be attached to the PO. Could you please help me out with the sample code.

Regards,

Saran.

9 REPLIES 9
Read only

MateuszAdamus
Active Contributor
2,715

Hello sarankumargsk

I assume you have the PDF file encoded in a BASE64 string, correct?

If yes, then you can convert BASE64 encoded string to XSTRING with function SCMS_BASE64_DECODE_STR. Then convert XSTRING to SOLIX_TAB with function SCMS_XSTRING_TO_BINARY. Then convert SOLIX_TAB to SOLI_TAB with SO_SOLIXTAB_TO_SOLITAB function

And then, in the end, use example from this blog (http://www.saptechnical.com/Tutorials/Smartforms/PO/Prg.htm) to add attachment to the document. Attachment is added in FILE_ATTACH procedure.

Kind regards,
Mateusz

Edit: To convert image to PDF you'd probably have to upload it to the application server (similar to what SE78 transaction does) and then print to OTF content, which will be converted to a PDF binary data. Then upload the PDF binary data to the document with GOS. After all that you can delete the uploaded image from the application server.

Here is a comment that describes just that: https://answers.sap.com/comments/7361754/view.html (read the following comments, too).

To upload the BASE64 encoded image you will need to convert it to XSTRING first, as described before.

Read only

former_member213475
Participant
0 Kudos
2,715

Hello Mateusz,

Thanks for your response.

Nope. I have an image file that is in BASE64 string format and this needs to be converted into PDF file.

Regards,

Saran.

Read only

0 Kudos
2,715

Hi sarankumargsk,
Just to be sure: your base64 encoded string is actually an image and you would like to generate a PDF file based on that image, is that correct?
Regards,
Bartosz

Read only

0 Kudos
2,097

I have a similar requirement,
I need to print that decoded pdf file on to an existing adobe form, any idea how can we do that.?

Read only

former_member213475
Participant
0 Kudos
2,715

Hi Bartosz,

Yup. You are right.

Regards,

Saran

Read only

2,715

I have updated my answer to meet your requirement. Please use the "Comment" option when replying to answers or providing more information to question.


Kind regards,
Mateusz
Read only

former_member213475
Participant
0 Kudos
2,715

Hi Mateusz,

Here I am getting the Image from API in the form of string. This string needs to be converted to PDF and finally, I need to attach the PDF to the PO. All these steps I am automating by writing the program. I am not performing any manual activities here. Can you please help me any FM's or sample code to these processes.

Regards,

Saran.

Read only

MateuszAdamus
Active Contributor
0 Kudos
2,715

Hello sarankumargsk

Please check the comment I posted a link to. There is a description on how to upload an image programmatically to the application server and then how to convert it to a PDF.


Kind regards,
Mateusz
Read only

Sandra_Rossi
Active Contributor
0 Kudos
2,715

"Image" bytes are transmitted as base64, but image is in what format? (PNG, JPG, GIF, BMP, TIFF, etc.)

NB: in case you don't know, base64 is a way of passing bytes as characters (3 bytes of values 0-255 are represented as 4 characters, among a list of 64 characters, 256*256*256 (2**(8+8+8)) = 64*64*64*64 (2**(6+6+6+6))). Look at wikipedia for more information.