smartforms生成 PDF 压缩后下载至PC端或发至mail

smartforms--->生成PDF如下:
 "smartforms 名称
     LSMNAME = ‘ZFIS0010‘.
     CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME‘   " 内定函数
        EXPORTING
           FORMNAME           = LSMNAME "‘ZFIS0010S‘
        IMPORTING
           FM_NAME            = L_NAME
        EXCEPTIONS
           NO_FORM            = 1
           NO_FUNCTION_MODULE = 2
        OTHERS             = 3.
   IF SY-SUBRC <> 0.
    " Call Smart Forms ERROR!
    MESSAGE S001 DISPLAY LIKE ‘E‘ WITH TEXT-E02.  " 提示表单错误
  ELSE.
*--->---smrt forms參數設定---
    LS_CONTROL-NO_DIALOG = ‘X‘.   " No dialog window
    LS_CONTROL-GETOTF    = ‘X‘.   " Get OTF data
    LS_CONTROL-LANGU     = ‘M‘.
    LS_CONTROL-NO_OPEN   = ‘X‘.
    LS_CONTROL-PREVIEW   = ‘X‘.
    LS_COMPOSER-TDDEST   = ‘FPW1‘.
    LS_COMPOSER-TDIMMED  = ‘X‘.   " print immediately

*--->---設定印表機--- " OTF: 直接下載檔案
    CALL FUNCTION ‘SSF_OPEN‘
     EXPORTING
       CONTROL_PARAMETERS = LS_CONTROL
       OUTPUT_OPTIONS     = LS_COMPOSER
       USER_SETTINGS = ‘‘
     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.

*--->---get OTF file---
    CLEAR: CH_OTF.

 " 动态调用新生成的函数
      CALL FUNCTION L_NAME
        EXPORTING
          USER_SETTINGS             = ‘‘
          CONTROL_PARAMETERS = LS_CONTROL
          OUTPUT_OPTIONS         = LS_COMPOSER
          ZUGDT                          = ANLA-ZUGDT
        G_TOTALLINES             = G_TOTALLINES
        IMPORTING
          JOB_OUTPUT_INFO         = CH_OTF
        TABLES
         GT_LYS      = GT_LYS
       EXCEPTIONS
        FORMATTING_ERROR      = 1
        INTERNAL_ERROR            = 2
        SEND_ERROR                 = 3
        USER_CANCELED         = 4
       OTHERS                            = 5.

    IF SY-SUBRC <> 0.
 " GET OTF data ERROR!
      MESSAGE S001 DISPLAY LIKE ‘E‘ WITH TEXT-E03. " 提示表单错误
    ENDIF.
" 调用完整代码 PERFORM 并取消部分的注释,
PERFORM SEND_PDF TABLES CH_OTF-OTFDATA. ENDIF.

完整代码如下:

REPORT  ZMM_PDF_ZPI_MAIL NO STANDARD PAGE HEADING
          MESSAGE-ID 00 LINE-SIZE 177 LINE-COUNT 200.
DATA:g_val        TYPE c,
     w_pripar     TYPE pri_params,
     w_arcpar     TYPE arc_params,
     input_length TYPE i,
     content_x    TYPE xstring,
     content_s    TYPE string,
     spool_no     LIKE tsp01-rqident,
     it_pdf       TYPE TABLE OF tline WITH HEADER LINE,
     wa_pdf       LIKE LINE OF it_pdf,
     file_tab     TYPE STANDARD TABLE OF solisti1,
     bin_file     TYPE xstring,
     bytecount    TYPE i,
     zip          TYPE xstring,
     path_table   TYPE TABLE OF char1024.
DATA: BEGIN OF it_t001 OCCURS 0,
        bukrs     TYPE t001-bukrs,
        butxt     TYPE t001-butxt,
      END OF it_t001.

DATA:LT_TLINE TYPE STANDARD TABLE OF TLINE WITH HEADER LINE.
DATA:  G_MAIL_ADDRESS TYPE AD_SMTPADR.
DATA:g_zipper     TYPE REF TO cl_abap_zip.
DATA:file_name    TYPE string VALUE ‘Report_output.pdf‘.
DATA:file_name2    TYPE string VALUE ‘Report_output2.pdf‘.
DATA:file_path    TYPE string VALUE ‘D:\temp\pdf_report.ZIP‘.

 SELECTION-SCREEN BEGIN OF BLOCK A WITH FRAME TITLE TEXT-BO1.

SELECT-OPTIONS: s_addr FOR g_mail_address
              NO INTERVALS DEFAULT‘[email protected]‘.
  SELECTION-SCREEN END OF BLOCK A.

START-OF-SELECTION.
  PERFORM get_data.
  PERFORM print_data CHANGING spool_no.
  PERFORM convert_spool_2_pdf.
  PERFORM convert_binary_2_xstring.

END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
FORM get_data .

  SELECT * FROM t001
    INTO CORRESPONDING FIELDS OF TABLE it_t001 UP TO 10 ROWS.

ENDFORM.                    " get_data
*&---------------------------------------------------------------------*
*&      Form  print_data
*&---------------------------------------------------------------------*
FORM print_data  CHANGING spool_no.
  CALL FUNCTION ‘GET_PRINT_PARAMETERS‘
    EXPORTING
      in_archive_parameters  = w_arcpar
      in_parameters          = w_pripar
      layout                 = ‘X_65_132‘
      line_count             = 65
      line_size              = 255
      no_dialog              = ‘X‘
    IMPORTING
      out_archive_parameters = w_arcpar
      out_parameters         = w_pripar
      valid                  = g_val.
  IF g_val  NE space AND sy-subrc = 0.
    w_pripar-prrel = space.
    w_pripar-primm = space.
    NEW-PAGE PRINT ON NEW-SECTION PARAMETERS w_pripar ARCHIVE PARAMETERS w_arcpar NO DIALOG.
    "Output which is gone to spool
    LOOP AT it_t001.
      WRITE:/ it_t001.
    ENDLOOP.
    NEW-PAGE PRINT OFF.
    CALL FUNCTION ‘ABAP4_COMMIT_WORK‘.
  ENDIF.
  IF NOT sy-spono IS INITIAL.
    spool_no = sy-spono.
  ENDIF.
ENDFORM.                    " print_data
*&---------------------------------------------------------------------*
*&      Form  convert_spool_2_pdf
*&---------------------------------------------------------------------*
FORM convert_spool_2_pdf .
  CALL FUNCTION ‘CONVERT_ABAPSPOOLJOB_2_PDF‘
    EXPORTING
      src_spoolid   = spool_no
      no_dialog     = space
    IMPORTING
      pdf_bytecount = bytecount
    TABLES
      pdf           = it_pdf.

*"---> pdf 内表格式转换固定格式
    CALL FUNCTION ‘SX_TABLE_LINE_WIDTH_CHANGE‘
    EXPORTING
      line_width_src = 134
      line_width_dst = 255
    TABLES
      content_in     = it_pdf
      content_out    = file_tab.

ENDFORM.  " convert_spool_2_pdf

*&---------------------------------------------------------------------*
*&      Form  convert_binary_2_xstring
*&---------------------------------------------------------------------*
FORM convert_binary_2_xstring .
  "create xstring from table
  CALL FUNCTION ‘SCMS_BINARY_TO_XSTRING‘
    EXPORTING
      input_length = bytecount
    IMPORTING
      buffer       = content_x
    TABLES
      binary_tab   = file_tab.

    PERFORM SEND_PDF ."TABLES CH_OTF-OTFDATA. "CH_OTF-OTFDATA 是 JOB_OUTPUT_INFO 返回的参数
*   PERFORM SEND_PDF TABLES CH_OTF-OTFDATA.
ENDFORM.      " convert_binary_2_xstring

FORM SEND_PDF. "TABLES IT_OTF STRUCTURE ITCOO
*  smartforms 传过来值请启用一下注释代码
*FORM SEND_PDF TABLES IT_OTF STRUCTURE ITCOO .

DATA: "LT_PDF TYPE STANDARD TABLE OF TLINE,
      L_PDF_FSIZE    TYPE I, " PDF XSTRING SIZE
      MSG1(50) TYPE C.

* ---CONVERT OTF TO PDF---
*  CALL FUNCTION ‘CONVERT_OTF‘
*    EXPORTING
*     FORMAT      = ‘PDF‘
*     MAX_LINEWIDTH    = 132
*      IMPORTING
*     BIN_FILESIZE     = L_PDF_FSIZE
*      TABLES
*     OTF    = IT_OTF
*     LINES       = IT_PDF
*      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.

*-----------------pdf mail 压缩文件 ---------------------
DATA:file_name    TYPE string VALUE ‘output.pdf‘,
         file_name2    TYPE string VALUE ‘output2.pdf‘,
         zip          TYPE xstring,
         l_obj_len2       TYPE i,
         file_path    TYPE string VALUE ‘D:\temp\pdf_out.ZIP‘,
         g_zipper     TYPE REF TO cl_abap_zip.

 "---> 转换 xstring
 CALL FUNCTION ‘SCMS_BINARY_TO_XSTRING‘
    EXPORTING
      input_length = bytecount
    IMPORTING
      buffer       = content_x
    TABLES
      binary_tab   = file_tab.

DATA: l_send_request  TYPE REF TO cl_bcs,
        l_zip           TYPE REF TO cl_abap_zip,
        l_sender        TYPE REF TO cl_sapuser_bcs,
        l_recipient     TYPE REF TO cl_cam_address_bcs,
        l_body_text     TYPE bcsy_text,
        l_obj_len       TYPE so_obj_len,
        l_subject       TYPE so_obj_des,
        l_exception     TYPE REF TO cx_bcs,
        l_message       TYPE string,
        l_content       TYPE solix_tab,
        l_html_xstr     TYPE xstring,
        lv_xstring TYPE xstring,
        l_zip_xstr      TYPE xstring,
        l_len           TYPE i,
        l_document      TYPE REF TO cl_document_bcs.

TRY.

      l_send_request = cl_bcs=>create_persistent( ).
      l_subject = ‘cl_abap_zip & cl_bcs example‘.
      APPEND:  ‘<HTML><BODY>‘   TO l_body_text,
                 ‘Hi,‘       TO l_body_text,
              ‘<p>Pls refer to the attached. Thanks.‘ TO l_body_text,
               ‘</BODY><HTML>‘       TO l_body_text.
      l_document = cl_document_bcs=>create_document(
                            i_type        = ‘HTM‘
                            i_text        = l_body_text
                            i_subject     = l_subject
                    ).

    CREATE OBJECT l_zip.
" 第一个pdf文件
      CALL METHOD l_zip->add
        EXPORTING
          name    = ‘cl_bcs example.PDF‘
          content = content_x.

" 第二个pdf文件
      CALL METHOD l_zip->add
        EXPORTING
          name    = ‘cl_bcs example2.PDF‘
          content = content_x.

*创建一个压缩文件
      CALL METHOD l_zip->save
        RECEIVING
          zip = l_zip_xstr.

      CALL METHOD cl_bcs_convert=>xstring_to_solix
        EXPORTING
          iv_xstring =  l_zip_xstr
        RECEIVING
          et_solix   = l_content.

*获取文件大小, ( XSTRLEN 计算文件大小 )
       l_obj_len = XSTRLEN( l_zip_xstr ) .

CALL METHOD l_document->add_attachment
        EXPORTING
          i_attachment_size    = l_obj_len
          i_attachment_type    = ‘ZIP‘
          i_attachment_subject = l_subject
          i_att_content_hex    = l_content.
      l_send_request->set_document( l_document ).
      l_sender = cl_sapuser_bcs=>create( sy-uname ).
      LOOP AT s_addr.
        l_recipient = cl_cam_address_bcs=>create_internet_address(
                        s_addr-low ).
        CALL METHOD l_send_request->add_recipient
          EXPORTING
            i_recipient = l_recipient.
      ENDLOOP.
      CALL METHOD l_send_request->set_send_immediately( ‘X‘ ).
      CALL METHOD l_send_request->send(
      EXPORTING
        i_with_error_screen  = ‘X‘
        ).
      COMMIT WORK.

      MESSAGE S001 WITH ‘邮件发送成功!‘ DISPLAY LIKE ‘S‘.
   CATCH cx_bcs INTO l_exception.
      l_message = l_exception->get_text( ).
      MESSAGE l_message TYPE ‘E‘.
  ENDTRY.

*      IF SY-SUBRC = 0.
*           MESSAGE S001 WITH ‘邮件发送成功!‘ DISPLAY LIKE ‘S‘.
*      ENDIF.
*----------------- end pdf mail 压缩文件 ---------------------

*-----------------pdf 压缩文件 载到本端 -------------------
*---->下载压缩 pdf文件
"创建 g_zipper 压缩文件
 CREATE OBJECT g_zipper.

  "第一个 pdf(xstring类型 )add file to zip
  CALL METHOD g_zipper->add
    EXPORTING
      name    = file_name
      content = content_x.

*   "第二个 pdf(xstring类型 )add file to zip
  CALL METHOD g_zipper->add
    EXPORTING
      name    = file_name2
      content = content_x.

*创建一个压缩文件
  CALL METHOD g_zipper->save
    RECEIVING
      zip = zip.

  l_obj_len2 = XSTRLEN( zip ) .

*字码转换 (xstring --> 二进制)
  CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY‘
    EXPORTING
      buffer        = zip
    IMPORTING
      output_length = l_obj_len2
    TABLES
      binary_tab    = file_tab.

*下载压缩文件到本端
  CALL FUNCTION ‘GUI_DOWNLOAD‘
    EXPORTING
      bin_filesize = l_obj_len2
      filename     = file_path
      filetype     = ‘BIN‘
    TABLES
      data_tab     = file_tab.
*----------------- end pdf 压缩文件 载到本端 -------------------
ENDFORM.

效果如下:

打开效果内容如下:

原文参考:https://wiki.scn.sap.com/wiki/display/ABAP/CL_ABAP_ZIP+usage+-+Zipping+ABAP+report+output

原文地址:https://www.cnblogs.com/Brokenshelltao/p/12145790.html

时间: 2024-10-13 07:30:32

smartforms生成 PDF 压缩后下载至PC端或发至mail的相关文章

C# 生成pdf文件客户端下载

itextsharp.dll 下载:http://sourceforge.net/projects/itextsharp/ 程序需引用:itextsharp.dll,itextsharp.pdfa.dll,PresentationFramework.dll 本人使用的是一般处理程序来写的,废话不多说代码才是硬道理,使用插件定位图片,表格是使用html转的pdf 1 public void ProcessRequest(HttpContext context) 2 { 3 context.Resp

图片压缩(pc端和移动端都适用)

最近在做移动端遇到了一个问题就是: 手机拍照后,图片过大如果上传到服务器务必会浪费带宽,最重要的是流量啊 别慌,好事儿来了,务必就会有人去研究研究图片的压缩: 鄙人结合前人的经验,结合自己实战,总结出一个方法供大家参考. /** * 图片压缩,默认同比例压缩 * @param {Object} path * pc端传入的路径可以为相对路径,但是在移动端上必须传入的路径是照相图片储存的绝对路径 * @param {Object} obj * obj 对象 有 width, height, qual

Gitbook 生成 pdf 中文字体错乱问题解决办法

Gitbook 生成 pdf 中文字体错乱问题解决办法 用过 Gitbook 的都知道, Gitbook 会自动生成 pdf 以提供下载, 但十分遗憾的是自动生成的 pdf 对中文的支持并不好, 经常出现字体不一致的现象, 影响阅读, 强迫症更是难以忍受. 示例: 下面针对这一问题提供简单的解决办法: 本地命令行生成 pdf 文件. 当然这种方法有一定局限性, 你需要找到托管在 github 对应的源码仓库且转换过程中不出错. (由于水平有限未能解决在线生成的pdf中文字体错乱问题, 见谅. 也

java文本、表格word转换生成PDF加密文件代码下载

原文:java文本.表格word转换生成PDF加密文件代码下载 代码下载地址:http://www.zuidaima.com/share/1550463239146496.htm 这个实现了PDF加密功能,和一些基本的问题. java文本.表格word转换生成PDF加密文件代码下载,布布扣,bubuko.com

java生成excel表格和pdf并实现下载弹出框

今天在pdf和excel中都实现了在浏览器弹出下载框 将之前在网上查找的生成excel表格代码稍微修改下: public class CreateSimpleExcelToDisk { /** * @功能:手工构建一个简单格式的Excel */ private static List<News> getNews() throws Exception { List<News> data = new ArrayList<News>(); NewsDao dao = new

Java 使用itext生成pdf以及下载

使用方法: 1.需要两个jar包: iText-5.0.6.jar    //必须使用该版本,否则缺少相关的方法 TextAsian.jar //是为了文档中正常显示中文所必须引用的包 TextAsian.jar使用时并不是单纯的引入就可以了,还需要进一步处理该jar包,否则无法显示 (无奈当时没有保存那个解决方法的链接,所以以后要用正确的包的话,就去毕设项目下找该包) 2以下是一个完整的例子. 一.要生成pdf的jsp页面 <%@ page language="java" im

PrestaShop 1.7 订单生成后下载服务器出现 505 的错误

PrestaShop 生成订单后下载,服务器上有 505 的错误. 经查看应该是服务器上的错误: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) 在默认情况下 PHP 的内存限制为 128MB,根据这个情况有可能你需要修改 php.ini 文件增加 PHP 内存的大小. 修改配置文件里面的 memory_limit 的配置到 256 MB 可以避免这个问题. 原文地址:http://blo

前端压缩图片代码,支持移动端和pc 端,还有拍照后获取到的照片

1. upload   使用者调用的方法 2. rotateImg  旋转照片,用于把iOS拍照后获取到的图片摆正 3. dataURLtoFile 将压缩后的图片转为file 对象,区分一个 blob 和 base64, 兼容哪个就用哪个 4. 得先引入  exif-js  用于拿到图片信息,确定 iOS 怎么旋转的 1 import EXIF from 'exif-js' 2 var picValue = null, 3 headerImage = '', 4 imgName = '', 5

移动端图片上传解决方案localResizeIMG先压缩后ajax无刷新上传

现在科技太发达,移动设备像素越来越高,随便一张照片2M+,但是要做移动端图片上传和pc上略有不同,移动端你不能去限制图片大小,让用户先处理图片再上传,这样不现实.所以理解的解决方案就是在上传先进行图片压缩,然后再把压缩后的图片上传到服务器. 一翻google之后,发现了localResizeIMG,它会对图片进行压缩成你指定宽度及质量度并转换成base64图片格式,那么我们就可以把这个base64通过ajax传到后台,再进行保存,先压缩后上传的目的就达到了. 处理过程 LocalResizeIM