‎2011 Jan 18 9:06 AM
Hi experts!
I want to convert a base64Binary file to PDF. I receive the base64Binary file from XI.
Can anyone help me??
Thanks all!!!
‎2011 Jan 18 11:57 AM
Hi ,
You can use below two step to create PDF File from binary data .
call function 'PRINT_TEXT'
exporting
device = 'PRINTER'
dialog = ' '
header = header
options = options
importing
result = result
tables
lines = lines
otfdata = otf.
* convert to PDF
call function 'CONVERT_OTF'
exporting
format = 'PDF'
importing
bin_filesize = 132
tables
otf = otf
lines = lines
‎2011 Jan 18 2:35 PM
SAP has built-in base64 encode/decode functions - see function group SSFC. If you intend to download and/or open the file, you will need to convert the resulting XSTRING using a function such as SCMS_XSTRING_TO_BINARY.
‎2011 Jan 19 8:23 AM
Thanks!
But I can't convert the text to PDF. Can you give me more examples??
Thanks!
‎2011 Jan 19 2:15 PM
‎2011 Jan 19 3:32 PM
‎2011 Jan 19 3:39 PM
I tried a lot of functions....
Option 1.
CALL FUNCTION 'SSFC_BASE64_DECODE'
EXPORTING
b64data = cad_xi
IMPORTING
bindata = l_cad
EXCEPTIONS
ssf_krn_error = 1
ssf_krn_noop = 2
ssf_krn_nomemory = 3
ssf_krn_opinv = 4
ssf_krn_input_data_error = 5
ssf_krn_invalid_par = 6
ssf_krn_invalid_parlen = 7
OTHERS = 8.
tline-tdline = l_string.
APPEND tline.
options-tddest = 'PDF'. "Nombre de impresora local
options-tdnewid = 'X'.
options-tdcopies = 1.
options-tdnoprint = 'X'.
options-tdimmed = 'X'.
options-tdgetotf = 'X'.
" With this code I'm trying to get the OTF conversion
CALL FUNCTION 'PRINT_TEXT'
EXPORTING
device = 'PDF'
header = header
OPTIONS = options
application = 'TX'
IMPORTING
RESULT = RESULT
tables
lines = tline
otfdata = oft
EXCEPTIONS
canceled = 1
device = 2
form = 3
OPTIONS = 4
unclosed = 5
unknown = 6
format = 7
textformat = 8
communication = 9
bad_pageformat_for_print = 10
OTHERS = 11.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_file = file
TABLES
otf = oft
lines = tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
Second option:
CALL METHOD cl_http_utility=>if_http_utility~decode_base64
EXPORTING
encoded = cad_xi
RECEIVING
decoded = lv_out_char_decoded.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = lv_out_char_decoded
mimetype = 'APPLICATION/PDF'
IMPORTING
buffer = lv_out_charx.
call function 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = lv_pdf_len
bin_file = lv_out_charx
TABLES
OTF = LT_OUTPUT_DATA-OTFDATA
LINES = LT_LINES
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
others = 5.
" With this FM I got the error number 4 -BAD OTF, because the table is emty
Thanks in advance.
‎2011 Jan 19 4:03 PM
I don't understand why you're calling CONVERT_OTF at all; maybe the suggestion by Harshmad threw you off - it was totally wrong. Your data is already in PDF format right? It's just base64 encoded for transmission? If you need to download it or open it, once you have it in XSTRING format (I would use the function I gave you, not the http helper class to go to STRING, then back to XSTRING), take it to a binary table with the SCMS function. Now it's ready for download/saving. I'm not sure what your end result needs to be; that's just an assumption on my part.
‎2011 Jan 19 4:26 PM
Thanks Brad,
But I can't understand you, because my english isn't very well...
Please can you summarize the steps that I have to follow.
THANKS!
‎2011 Jan 20 9:27 AM
Hi Brad,
I have followed the next steps but the program doesn't work.
My code is:
" I convert the text I received from XI to XSTRING
CALL FUNCTION 'SSFC_BASE64_DECODE'
EXPORTING
b64data = cad_xi
IMPORTING
bindata = l_cad
EXCEPTIONS
ssf_krn_error = 1
ssf_krn_noop = 2
ssf_krn_nomemory = 3
ssf_krn_opinv = 4
ssf_krn_input_data_error = 5
ssf_krn_invalid_par = 6
ssf_krn_invalid_parlen = 7
OTHERS = 8.
" I convert the XSTRING to binary
DATA binary_tab TYPE STANDARD TABLE OF x255 WITH HEADER LINE.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = l_cad
TABLES
binary_tab = binary_tab.
" And then I downloaded the binary text -> But It doesn't work....