smartforms 转 PDF 直接下载至本地

1.定义

DATA: gd_path TYPE string.

DATA: g_fmname TYPE rs38l_fnam.

DATA: lw_ctrl_param TYPE ssfctrlop,
      lw_out_option TYPE ssfcompop.

DATA: ls_job_output_info TYPE ssfcrescl.

DATA: t_otf     TYPE itcoo OCCURS 0 WITH HEADER LINE,
      t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA: w_bin_filesize TYPE i.

DATA: lv_filename TYPE string.

2.保存地址弹框

PARAMETERS: p_path TYPE string .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
  CALL METHOD cl_gui_frontend_services=>directory_browse
    EXPORTING
      window_title    = 'File Directory'
      initial_folder  = 'C:'
    CHANGING
      selected_folder = gd_path.
  CALL METHOD cl_gui_cfw=>flush.
  CONCATENATE gd_path '' INTO p_path.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = 'ZFQM00402'
    IMPORTING
      fm_name            = g_fmname
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.

3.打印属性设置

  lw_ctrl_param-no_dialog = 'X'.
  lw_ctrl_param-preview = space.
  lw_ctrl_param-getotf = 'X'.
  lw_ctrl_param-no_open = 'X'.      "不弹出打印请求
  lw_ctrl_param-no_close = 'X'.     "不添加打印请求
  lw_ctrl_param-no_open = space.    "弹出打印请求
  lw_ctrl_param-preview = ''. "打印预览

  lw_out_option-tddest = 'LP02'.
  lw_out_option-tddest = lw_job_output_options-tddest.   "取得打印机
  lw_out_option-tdimmed = 'X'.      "立即假脱机打印
  lw_out_option-tddelete = 'X'.     "立即假脱机删除

4.转PDF并下载

  CALL FUNCTION g_fmname
    EXPORTING
      control_parameters = lw_ctrl_param
      output_options     = lw_out_option
      user_settings      = ''
*     iwqm00402_h        = gw_h
*     iwqm00402_tail     = gw_tail
    IMPORTING
      job_output_info    = ls_job_output_info
*  TABLES
*     itqm00402_t        = gt_t
*     itqm00402_charg    = gt_charg1
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 5.

  t_otf[] = ls_job_output_info-otfdata[].

  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
      max_linewidth         = 132
    IMPORTING
      bin_filesize          = w_bin_filesize
    TABLES
      otf                   = t_otf
      lines                 = t_pdf_tab
    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.

  CONCATENATE p_path 'XXX''.pdf' INTO lv_filename.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      bin_filesize            = w_bin_filesize
      filename                = lv_filename
      filetype                = 'BIN'
    TABLES
      data_tab                = t_pdf_tab
    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.
  ELSE.
    MESSAGE '保存成功!' TYPE 'S'.
  ENDIF.

5.乱码问题
可以考虑换语言环境以及打印输出设备如LP01->LP02
转:

http://blog.chinaunix.net/uid-20692741-id-1892901.html
http://www.itpub.net/thread-960886-1-1.html

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页