2013 Oct 24 12:07 AM
Hi all,
My requirement is to convert PDF docuement to Base64Binary format. I checked all the forums but none of them resolved my issue. The below tool gives the exact format(Base64Binary) by taking PDF document as input. Please make sure that the PDF document should not be either scanned or emailed but it should be direclty downloaded from any website.
http://www.motobit.com/util/base64-decoder-encoder.asp.
Thanks,
Baasanthi.
2013 Oct 24 7:30 AM
Hi,
Check My code below.
Which first take a pdf file as input and convert it into the base64 fromat.I have used the FM GUI_UPLOAD for doing this.
Steps1: Get the file path using class cl_gui_frontend_services=>file_open_dialog.
step2 : Pass the path (file name to the FM GUI_UPLOAD).
Step3 : Convert resultant binary to xstring)
step4 : Convert xstring to base64 format.
DATA : file_table TYPE filetable,
rc TYPE i.
DATA : filesize TYPE i.
DATA : xstr TYPE xstring.
DATA : base64 TYPE string.
DATA : lx_wa(1024) TYPE c.
TYPES : BEGIN OF ty_binary,
binary_field TYPE text,"(1000) TYPE c,
END OF ty_binary.
DATA : hex_tab1 TYPE TABLE OF ty_binary WITH HEADER LINE.
PARAMETERS : p_dest TYPE string.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dest.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
CHANGING
file_table = file_table
rc = rc.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
READ TABLE file_table INTO lx_wa INDEX 1.
p_dest = lx_wa.
START-OF-SELECTION.
CALL METHOD cl_gui_frontend_services=>file_get_size
EXPORTING
file_name = p_dest
IMPORTING
file_size = filesize.
CALL METHOD cl_gui_cfw=>flush( ).
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_dest
filetype = 'BIN'
TABLES
data_tab = hex_tab1.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = filesize
* FIRST_LINE = 0
* LAST_LINE = 0
IMPORTING
buffer = xstr
TABLES
binary_tab = hex_tab1
* EXCEPTIONS
* FAILED = 1
* OTHERS = 2
.
IF sy-subrc = 0.
CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
EXPORTING
input = xstr
IMPORTING
output = base64.
WRITE : 'BASE 64:' , base64.
ENDIF.
Regards,
Alenlee MJ
2013 Oct 24 2:02 AM
Hi,
Check the function module SCMS_BASE64_ENCODE_STR...
Cheers,
Phil
2013 Oct 24 7:30 AM
Hi,
Check My code below.
Which first take a pdf file as input and convert it into the base64 fromat.I have used the FM GUI_UPLOAD for doing this.
Steps1: Get the file path using class cl_gui_frontend_services=>file_open_dialog.
step2 : Pass the path (file name to the FM GUI_UPLOAD).
Step3 : Convert resultant binary to xstring)
step4 : Convert xstring to base64 format.
DATA : file_table TYPE filetable,
rc TYPE i.
DATA : filesize TYPE i.
DATA : xstr TYPE xstring.
DATA : base64 TYPE string.
DATA : lx_wa(1024) TYPE c.
TYPES : BEGIN OF ty_binary,
binary_field TYPE text,"(1000) TYPE c,
END OF ty_binary.
DATA : hex_tab1 TYPE TABLE OF ty_binary WITH HEADER LINE.
PARAMETERS : p_dest TYPE string.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dest.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
CHANGING
file_table = file_table
rc = rc.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
READ TABLE file_table INTO lx_wa INDEX 1.
p_dest = lx_wa.
START-OF-SELECTION.
CALL METHOD cl_gui_frontend_services=>file_get_size
EXPORTING
file_name = p_dest
IMPORTING
file_size = filesize.
CALL METHOD cl_gui_cfw=>flush( ).
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_dest
filetype = 'BIN'
TABLES
data_tab = hex_tab1.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = filesize
* FIRST_LINE = 0
* LAST_LINE = 0
IMPORTING
buffer = xstr
TABLES
binary_tab = hex_tab1
* EXCEPTIONS
* FAILED = 1
* OTHERS = 2
.
IF sy-subrc = 0.
CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
EXPORTING
input = xstr
IMPORTING
output = base64.
WRITE : 'BASE 64:' , base64.
ENDIF.
Regards,
Alenlee MJ
2013 Oct 24 7:30 PM
Hi Alenlee,
Thanks a lot this is working perfectly..........
Thanks,
Baasanthi.