SMARTFORMS打印转PDF并文件保存
问题:普通SMARTFORMS打印,无法实现转PDF后进行一系列其他操作。
解决办法:使用函数将OTF类型数据转换为PDF。
代码如下:
打印无弹窗,直接转PDF后并保存文件到本地。
"定义打印变量 DATA:fm_name TYPE rs38l_fnam, ""打印程序函数名 lv_formname TYPE tdsfname VALUE 'ZTEST_01'. "SMARTFORMS名字 "打印参数 DATA:control TYPE ssfctrlop, output_options TYPE ssfcompop, l_job_output_info TYPE ssfcrescl. " PDF变量 DATA:lv_file_size TYPE i, "PDF文件大小 lv_bin_fiel TYPE xstring, "二进制文件流 lt_lines TYPE STANDARD TABLE OF tline, lt_otfdata TYPE tsfotf. "OTF数据 "打印参数赋值 control-no_dialog = 'X'."打印不显示 control-getotf = 'X'."返回OTF表 control-langu = sy-langu. output_options-tddest = 'LP01'."假脱机:设备名 output_options-tdimmed = 'X'."立即假脱机打印 output_options-tddelete = 'X'."立即假脱机删除 "获取打印程序函数名 CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = lv_formname "创建的FORM名称 IMPORTING fm_name = fm_name "获取打印程序函数名 EXCEPTIONS no_form = 1 no_function_module = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. "开始打印 CALL FUNCTION fm_name EXPORTING output_options = output_options control_parameters = control user_settings = '' IMPORTING job_output_info = l_job_output_info "获取返回的打印数据 * TABLES * gt_item = lt_item2 "导入的行项目内表 EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 user_canceled = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. "OTF数据赋值 APPEND LINES OF l_job_output_info-otfdata TO lt_otfdata. "SMARTFORMS转PDF CALL FUNCTION 'CONVERT_OTF' EXPORTING format = 'PDF' * MAX_LINEWIDTH = 132 * ARCHIVE_INDEX = ' ' * COPYNUMBER = 0 * ASCII_BIDI_VIS2LOG = ' ' * PDF_DELETE_OTFTAB = ' ' pdf_username = sy-uname * PDF_PREVIEW = ' ' * USE_CASCADING = ' ' * MODIFIED_PARAM_TABLE = IMPORTING bin_filesize = lv_file_size bin_file = lv_bin_fiel TABLES otf = lt_otfdata lines = lt_lines EXCEPTIONS err_max_linewidth = 1 err_format = 2 err_conv_not_possible = 3 err_bad_otf = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ***BEGIN&-------------------保存PDF文件到本地----------------****************************** DATA: lv_filename TYPE string, "保存pdf文件名 lv_path TYPE string, lv_fullpath TYPE string, "文件全路径 lv_user_act TYPE i. "用户操作类型 lv_filename = 'mmmmmmm.pdf'. CALL METHOD cl_gui_frontend_services=>file_save_dialog "保存文件 窗口 EXPORTING window_title = '保存文件' default_extension = 'PDF' "文件后缀 default_file_name = lv_filename "文件名 * with_encoding = file_filter = '*.PDF' * initial_directory = prompt_on_overwrite = 'X' CHANGING filename = lv_filename path = lv_path fullpath = lv_fullpath user_action = lv_user_act "用户操作类型 * file_encoding = EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 3 invalid_default_file_name = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. IF lv_user_act = cl_gui_frontend_services=>action_cancel. MESSAGE '取消存取' TYPE 'S' DISPLAY LIKE 'E'. ENDIF. ENDIF. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING bin_filesize = lv_file_size filename = lv_fullpath filetype = 'BIN' * APPEND = ' ' * IMPORTING * FILELENGTH = TABLES data_tab = lt_lines * FIELDNAMES = EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ***EDN&-------------------保存PDF文件到本地----------------******************************