Sample Code

Download Adobe (PDF) form as pdf in local drive

This is a shell program which details the key elements for downloading an adobe form or pdf form to local drive. Please note, this is not a fully executable program and you need to develop your own business and form logic.

Let’s begin. The first thing which we need to do is to populate some additional parameters in the outputparam table.


s_outputparams-device     = 'PRINTER'.
  s_outputparams-dest         = v_printer.
  s_outputparams-nodialog  = abap_true.
*
<strong>  s_outputparams-preview   = abap_false.
  s_outputparams-getpdf     = abap_true.
</strong>
  s_outputparams-reqnew   = abap_true.

  s_outputparams-preview    = ''.

* Required if you want to assemble all pdfforms in one file.
<strong>  s_outputparams-assemble  = abap_true.
 
  s_outputparams-bumode   = 'M'.
  s_outputparams-getpdf      = 'M'.
</strong>
  CALL FUNCTION 'FP_JOB_OPEN'
    CHANGING
      ie_outputparams = s_outputparams
    EXCEPTIONS
      cancel          = 1
      usage_error     = 2
      system_error    = 3
      internal_error  = 4
      OTHERS          = 5.
  IF sy-subrc &lt;> 0.
* Implement suitable error handling here
  ENDIF.

Then call the form normally.


  CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
    EXPORTING
      i_name     = v_formname
    IMPORTING
      e_funcname = v_formnamefunction.

 CALL FUNCTION v_formnamefunction
    EXPORTING
      /1bcdwb/docparams  = s_docparam
      is_data            = t_data
    IMPORTING
      /1bcdwb/formoutput = s_formout
    EXCEPTIONS
      usage_error        = 1
      system_error       = 2
      internal_error     = 3
      OTHERS             = 4.

  CALL FUNCTION 'FP_JOB_CLOSE'.

DATA t_pdf_table TYPE              tfpcontent.

  REFRESH t_pdf_table.
* This FM will give you the PDF data in a string.
<strong>  CALL FUNCTION 'FP_GET_PDF_TABLE'
    IMPORTING
      e_pdf_table = t_pdf_table.</strong>

Now that you have PDF data in a string, you can send it as attachment, xml or download it as PDF. Follow to download as PDF file.


  DATA: lv_filename  TYPE string,
        t_att_content_hex TYPE solix_tab,
        ls_pdf_table LIKE LINE OF t_pdf_table,
        lv_path      TYPE char50.

  READ TABLE t_pdf_table INTO ls_pdf_table INDEX 1.

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer     = ls_pdf_table
    TABLES
      binary_tab = t_att_content_hex.

 CONDENSE lv_path.

  CONCATENATE lv_path v_filename '.pdf' INTO lv_filename.

  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
*     bin_filesize            = lv_length
      filename                = lv_filename
      filetype                = 'BIN'
* *  IMPORTING
* *    filelength                =
    CHANGING
      data_tab                = t_att_content_hex
    EXCEPTIONS
      file_write_error        = 1.

If you like the post, do share it with your colleagues and friends and like and follow our social media channels.

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)

Follow by Email
Twitter
LinkedIn
LinkedIn
Share