Search This Blog

Saturday, July 30, 2011

Download Smartform Output in PDF Format

SAP Smart Forms are used to create and maintain forms for mass printing in SAP Systems. As an output
medium SAP Smart Forms support a printer, a fax, e-mail. Many a times there is requirement to download
output of SAP Smart Forms in a PDF file.
Adobe® Portable Document Format (PDF) is a universal file format that contains all fonts, formats, and graphics. PDF files are widely used in the Internet, not least because the content of a PDF file cannot be changed, in contrast to Word.
Smart Forms does not support direct output in PDF format. Instead, the OTF output has to be converted to PDF. Fonts and code pages used have to be correct in the OTF output and are dependent on the language in which the form is printed. Depending on the language, a different device type that supports the corresponding fonts has to be used for printing.
A device type for printing PDF or for creating a PDF file is therefore not adequate for a Smart Form that is used as a template for printing forms in a number of languages. The device type has to be set dynamically before the Smart Forms function module is called.

Converting the smartform to PDF is process of 3 simple steps.
  • Calling the Smart form, then it returns the OTF data in Return.
  • Converting the OTF data into required format using the Function Module CONVERT_OTF_2_PDF.
  • Download the File

1. Call function module SSF_FUNCTION_MODULE_NAME. It returns the name of the generated function module. Call the generated function module.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    FORMNAME                 = 'SMARTFORM-NAME'
  IMPORTING
   
FM_NAME                  = FMNAME .

2. To get a device type suitable for the current language, call the function module SSF_GET_DEVICE_TYPE.

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
  EXPORTING
    I_LANGUAGE                   = 'E'
  IMPORTING
   E_DEVTYPE                    = v_e_devtype  .




3. Call Smartform

CALL
 FUNCTION FMNAME
 EXPORTING
   CONTROL_PARAMETERS         = st_control_parameters
   OUTPUT_OPTIONS             = st_output_options
  IMPORTING
   DOCUMENT_OUTPUT_INFO       = st_document_output_info
   JOB_OUTPUT_INFO            = st_job_output_info
   JOB_OUTPUT_OPTIONS         = st_job_output_options
  TABLES
    ITAB                       = ITAB
    ITAB1                      = ITAB1     .


4. Call the function module 'CONVERT_OTF_2_PDF' to convert the smart form to PDF format. The function module returns the size of downloaded file.

CALL FUNCTION 'CONVERT_OTF_2_PDF'
  IMPORTING
   BIN_FILESIZE                 = v_bin_filesize
  TABLES
    OTF                          = st_job_output_info-otfdata
    DOCTAB_ARCHIVE               = it_docs
    LINES                        = it_lines    .


5. You can then store the PDF output using the function module GUI_DOWNLOAD, for example, as a local file on your PC.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
   BIN_FILESIZE                    = v_bin_filesize
   FILENAME                       = 'SMART'
   FILETYPE                        = 'BIN'
  TABLES
    DATA_TAB                        = it_lines
          .