Объединить несколько PDF файлов в один
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
TRY. DATA: lv_rc TYPE i. DATA: it_files TYPE filetable. DATA: lv_action TYPE i. cl_gui_frontend_services=>file_open_dialog( EXPORTING file_filter = |pdf (*.pdf)\|*.pdf\|{ cl_gui_frontend_services=>filetype_all }| multiselection = abap_true CHANGING file_table = it_files rc = lv_rc user_action = lv_action ). IF lv_action = cl_gui_frontend_services=>action_ok. IF lines( it_files ) > 1. DATA(o_pdf_merger) = NEW cl_rspo_pdf_merge( ). LOOP AT it_files ASSIGNING FIELD-SYMBOL(<f>). DATA(lv_filesize) = CONV w3param-cont_len( '0' ). DATA(it_bin_data) = VALUE w3mimetabtype( ). cl_gui_frontend_services=>gui_upload( EXPORTING filename = |{ it_files[ sy-tabix ]-filename }| filetype = 'BIN' IMPORTING filelength = lv_filesize CHANGING data_tab = it_bin_data ). DATA(lv_bin_data) = cl_bcs_convert=>solix_to_xstring( it_solix = it_bin_data ). o_pdf_merger->add_document( lv_bin_data ). WRITE: / |Hinzugefügt: { it_files[ sy-tabix ]-filename } ({ lv_filesize } Bytes)|. ENDLOOP. o_pdf_merger->merge_documents( IMPORTING merged_document = DATA(lv_merged_pdf) rc = lv_rc ). IF lv_rc = 0. DATA: lv_filename TYPE string. DATA: lv_fullpath TYPE string. DATA: lv_path TYPE string. cl_gui_frontend_services=>file_save_dialog( EXPORTING default_extension = 'pdf' default_file_name = 'merged.pdf' file_filter = |pdf (*.pdf)\|*.pdf\|{ cl_gui_frontend_services=>filetype_all }| prompt_on_overwrite = abap_true CHANGING filename = lv_filename path = lv_path fullpath = lv_fullpath user_action = lv_action ). IF lv_action EQ cl_gui_frontend_services=>action_ok. DATA(it_bin_data_merged) = cl_bcs_convert=>xstring_to_solix( lv_merged_pdf ). DATA(lv_size_merged) = xstrlen( lv_merged_pdf ). cl_gui_frontend_services=>gui_download( EXPORTING filename = lv_fullpath filetype = 'BIN' bin_filesize = lv_size_merged CHANGING data_tab = it_bin_data_merged ). WRITE: / |Gespeichert: { lv_fullpath } ({ lv_size_merged } Bytes)|. ENDIF. ENDIF. ENDIF. ENDIF. CATCH cx_root INTO DATA(e_txt). WRITE: / e_txt->get_text( ). ENDTRY. |