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

Convert base64Binary file to PDF file

0 Likes
3,720

Hi experts!

I want to convert a base64Binary file to PDF. I receive the base64Binary file from XI.

Can anyone help me??

Thanks all!!!

9 REPLIES 9
Read only

harsh_soni2
Explorer
0 Likes
1,969

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

Read only

brad_bohn
Active Contributor
0 Likes
1,969

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.

Read only

0 Likes
1,969

Thanks!

But I can't convert the text to PDF. Can you give me more examples??

Thanks!

Read only

0 Likes
1,969

Can anyone help me, please???

Read only

brad_bohn
Active Contributor
0 Likes
1,969

Post the code that you tried...

Read only

0 Likes
1,969

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.

Read only

brad_bohn
Active Contributor
0 Likes
1,969

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.

Read only

0 Likes
1,969

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!

Read only

0 Likes
1,969

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....