标签:gv lo 合并 lv ABAP pdf PDF TYPE response
1.读取本地PDF文件夹
1 *&---------------------------------------------------------------------* 2 *& Report Z3426PDF001 3 *&---------------------------------------------------------------------* 4 *& 5 *&---------------------------------------------------------------------* 6 REPORT z3426pdf001. 7 DATA:gv_xcontent TYPE xstring. 8 PARAMETERS:p_path TYPE string DEFAULT 'C:\Users\3426\Desktop\PDFTEST'. 9 10 AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. 11 PERFORM frm_file_search CHANGING p_path. 12 13 START-OF-SELECTION. 14 PERFORM frm_upload_data. 15 PERFORM frm_upload_to_http. 16 17 FORM frm_upload_data. 18 DATA:lv_filter TYPE string, 19 lv_count TYPE i, 20 lv_filename TYPE string, 21 lt_file TYPE line OCCURS 0 WITH HEADER LINE, 22 lt_data TYPE STANDARD TABLE OF raw255, 23 lo_pdf TYPE REF TO cl_rspo_pdf_merge. 24 lv_filter = `*.pdf`. 25 CALL METHOD cl_gui_frontend_services=>directory_list_files 26 EXPORTING 27 directory = p_path 28 filter = lv_filter 29 files_only = abap_true 30 CHANGING 31 file_table = lt_file[] 32 count = lv_count 33 EXCEPTIONS 34 cntl_error = 1 35 directory_list_files_failed = 2 36 wrong_parameter = 3 37 error_no_gui = 4 38 not_supported_by_gui = 5 39 OTHERS = 6. 40 41 CREATE OBJECT lo_pdf. 42 LOOP AT lt_file INTO DATA(ls_file). 43 CLEAR:lt_data,gv_xcontent. 44 lv_filename = p_path && '\' && ls_file-line. 45 CALL METHOD cl_gui_frontend_services=>gui_upload 46 EXPORTING 47 filename = lv_filename 48 filetype = 'BIN' 49 IMPORTING 50 filelength = lv_count 51 CHANGING 52 data_tab = lt_data. 53 54 CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' 55 EXPORTING 56 input_length = lv_count 57 IMPORTING 58 buffer = gv_xcontent 59 TABLES 60 binary_tab = lt_data. 61 62 lo_pdf->add_document( gv_xcontent ). 63 ENDLOOP. 64 lo_pdf->merge_documents( IMPORTING merged_document = gv_xcontent rc = DATA(lv_rc) ). 65 FREE lo_pdf. 66 ENDFORM. 67 68 FORM frm_upload_to_http. 69 DATA:lo_response TYPE REF TO if_http_response, 70 lv_hostname TYPE string, 71 lv_port TYPE string. 72 73 CREATE OBJECT lo_response TYPE cl_http_response EXPORTING add_c_msg = 1. 74 lo_response->set_data( gv_xcontent ). 75 lo_response->set_header_field( name = if_http_header_fields=>content_type value = '.pdf' ). 76 lo_response->set_status( code = 200 reason = 'OK' ). 77 lo_response->server_cache_expire_rel( expires_rel = 600 ). 78 79 CALL FUNCTION 'TH_GET_VIRT_HOST_DATA' 80 EXPORTING 81 protocol = 0 82 virt_idx = 0 83 IMPORTING 84 hostname = lv_hostname 85 port = lv_port. 86 87 DATA(lv_guid) = cl_system_uuid=>create_uuid_x16_static( ). 88 DATA(lv_url) = |http://{ lv_hostname }:{ lv_port }/sap/public/{ lv_guid }.pdf|. 89 cl_http_server=>server_cache_upload( url = lv_url response = lo_response ). 90 cl_gui_frontend_services=>execute( document = lv_url ). 91 FREE lo_response. 92 ENDFORM. 93 94 FORM frm_file_search CHANGING p_path. 95 CALL METHOD cl_gui_frontend_services=>directory_browse 96 EXPORTING 97 window_title = '请选择文件打开目录' 98 initial_folder = 'C' 99 CHANGING 100 selected_folder = p_path. 101 102 CALL METHOD cl_gui_cfw=>flush. 103 ENDFORM.View Code
2.读取服务器指定路径下PDF文件夹
1 *&---------------------------------------------------------------------* 2 *& Report Z3426pdf002 3 *&---------------------------------------------------------------------* 4 *& 5 *&---------------------------------------------------------------------* 6 REPORT z3426pdf002. 7 DATA:gv_xcontent TYPE xstring. 8 PERFORM frm_get_data. 9 PERFORM frm_upload_to_http. 10 11 FORM frm_get_data. 12 DATA:lv_dir TYPE epsf-epsdirnam VALUE '/tmp/3426/lo_pdf', 13 lv_line TYPE xstring, 14 lt_dir TYPE TABLE OF epsfili, 15 lo_pdf TYPE REF TO cl_rspo_pdf_merge. 16 CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING' 17 EXPORTING 18 dir_name = lv_dir 19 TABLES 20 dir_list = lt_dir. 21 CREATE OBJECT lo_pdf. 22 23 LOOP AT lt_dir INTO DATA(ls_dir). 24 CLEAR:lv_line,gv_xcontent. 25 DATA(gv_absfile) = lv_dir && '/' && ls_dir-name. 26 OPEN DATASET gv_absfile FOR INPUT IN BINARY MODE. 27 DO. 28 READ DATASET gv_absfile INTO lv_line. 29 IF sy-subrc NE 0. 30 EXIT. 31 ENDIF. 32 gv_xcontent = gv_xcontent && lv_line. 33 ENDDO. 34 CLOSE DATASET gv_absfile. 35 lo_pdf->add_document( gv_xcontent ). 36 ENDLOOP. 37 lo_pdf->merge_documents( IMPORTING merged_document = gv_xcontent rc = DATA(lv_rc) ). 38 FREE lo_pdf. 39 ENDFORM. 40 41 FORM frm_upload_to_http. 42 DATA:lo_response TYPE REF TO if_http_response, 43 lv_hostname TYPE string, 44 lv_port TYPE string. 45 46 CREATE OBJECT lo_response TYPE cl_http_response EXPORTING add_c_msg = 1. 47 lo_response->set_data( gv_xcontent ). 48 lo_response->set_header_field( name = if_http_header_fields=>content_type value = '.pdf' ). 49 lo_response->set_status( code = 200 reason = 'OK' ). 50 lo_response->server_cache_expire_rel( expires_rel = 600 ). 51 52 CALL FUNCTION 'TH_GET_VIRT_HOST_DATA' 53 EXPORTING 54 protocol = 0 55 virt_idx = 0 56 IMPORTING 57 hostname = lv_hostname 58 port = lv_port. 59 60 DATA(lv_guid) = cl_system_uuid=>create_uuid_x16_static( ). 61 DATA(lv_url) = |http://{ lv_hostname }:{ lv_port }/sap/public/{ lv_guid }.pdf|. 62 cl_http_server=>server_cache_upload( url = lv_url response = lo_response ). 63 cl_gui_frontend_services=>execute( document = lv_url ). 64 FREE lo_response. 65 ENDFORM.View Code
标签:gv,lo,合并,lv,ABAP,pdf,PDF,TYPE,response 来源: https://www.cnblogs.com/1187163927ch/p/16117619.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。