Skip to Content
Technical Articles
Author's profile photo chirag kalaria

Disable Save Button In Adobe Form Print Preview

Introduction

 

Hi all,

This blog is related to Adobe Form print preview. There are many client’s who request to prevent save of PDF file from print preview screen. Will show how to do it with sample program.

 

Prerequisites

 

Need to change below setting in SAP GUI in HTML Control.

SAP%20GUI%20Settings

SAP GUI Settings

Step-By-Step Process

Step – 1

Created sample Adobe Form with name – ZTEST_FORM.

Step – 2

Create sample program to display Adobe Form for as below.

This program contains two part based on check box selection

  • Normal Adobe Form Preview with help of below function call

          FP_JOB_OPEN

          FP_FUNCTION_MODULE_NAME

          CALL FUNCTION lv_funcname

          FP_JOB_CLOSE

  • PDF in custom container which will disable Save as/Print/Save ( Toolbar & Right Click Event)
*&---------------------------------------------------------------------*
*& Report ZDISABLE_SAVE_ADOBE
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zdisable_save_adobe.

DATA: html_viewer     TYPE REF TO cl_gui_html_viewer,
      main_container  TYPE REF TO cl_gui_custom_container,
      gv_bin_filesize TYPE i,
      gt_lines        TYPE STANDARD TABLE OF tdline,
      gt_html         TYPE TABLE OF w3_html,
      gs_html         TYPE w3_html,
      gt_swastrtab    TYPE STANDARD TABLE OF swastrtab,
      gs_swastrtab    TYPE swastrtab,
      gv_content      TYPE xstring,
      gv_encoded      TYPE string,
      gv_html         TYPE string,
      gv_url          TYPE char255.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.

  PARAMETERS : p_save TYPE flag AS CHECKBOX.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

  DATA :lv_outputparams TYPE sfpoutputparams,
        lv_funcname     TYPE funcname,
        lv_docparams    TYPE sfpdocparams,
        is_formoutput   TYPE fpformoutput.

  IF p_save = abap_true.
    lv_outputparams-nopreview = abap_true.
    lv_outputparams-getpdf    = abap_true.
  ELSE.
    lv_outputparams-preview   = abap_true.
  ENDIF.
  lv_outputparams-nodialog  = abap_true.
  lv_outputparams-dest      = 'ZLP1'.

  CALL FUNCTION 'FP_JOB_OPEN'
    CHANGING
      ie_outputparams = lv_outputparams
    EXCEPTIONS
      cancel          = 1
      usage_error     = 2
      system_error    = 3
      internal_error  = 4
      OTHERS          = 5.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

  CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
    EXPORTING
      i_name     = 'ZTEST_FORM'
    IMPORTING
      e_funcname = lv_funcname.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

  IF lv_funcname IS NOT INITIAL.
    CALL FUNCTION lv_funcname
      EXPORTING
        /1bcdwb/docparams  = lv_docparams
      IMPORTING
        /1bcdwb/formoutput = is_formoutput
      EXCEPTIONS
        usage_error        = 1
        system_error       = 2
        internal_error     = 3
        OTHERS             = 4.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.
    IF is_formoutput-pdf IS NOT INITIAL.
      IF p_save = abap_true.
        CLEAR gv_content.
        gv_content = is_formoutput-pdf.

        CLEAR gv_bin_filesize.
        REFRESH gt_lines[].
        CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
          EXPORTING
            buffer        = gv_content
          IMPORTING
            output_length = gv_bin_filesize
          TABLES
            binary_tab    = gt_lines.

        CALL FUNCTION 'SSFC_BASE64_ENCODE'
          EXPORTING
            bindata                  = gv_content
            binleng                  = gv_bin_filesize
          IMPORTING
            b64data                  = gv_encoded
          EXCEPTIONS
            ssf_krn_error            = 1
            ssf_krn_noop             = 2
            ssf_krn_nomemory         = 3
            ssf_krn_opinv            = 4
            ssf_krn_input_data_error = 5
            ssf_krn_invalid_par      = 6
            ssf_krn_invalid_parlen   = 7
            OTHERS                   = 8.
        IF sy-subrc <> 0.
* Implement suitable error handling here
        ENDIF.

        CONCATENATE '<!DOCTYPE html>'
                    '<html>'
                    '<head>'
                    '<title>'
                    'test'
                    '</title>'
                    '</head>'
                    '<body>'
                    '<embed' INTO gv_html.

        CONCATENATE gv_html
                    'src="data:application/pdf;base64,'INTO gv_html SEPARATED BY space.

        CONCATENATE gv_html
                    gv_encoded INTO gv_html.

        CONCATENATE gv_html
                    '#toolbar=0&scrollbar=0&navpanes=0&embedded=true&statusbar=0&view=Fit;'
                    'readonly=true;disableprint=true;" " width="1170" height="800" style="border:none;" >'
                    '</embed>'
                    '</body>'
                    '</html>' INTO gv_html.

        CALL FUNCTION 'SWA_STRING_SPLIT'
          EXPORTING
            input_string                 = gv_html
            max_component_length         = 255
          TABLES
            string_components            = gt_swastrtab
          EXCEPTIONS
            max_component_length_invalid = 1
            OTHERS                       = 2.
        IF sy-subrc <> 0.
* Implement suitable error handling here
        ENDIF.

        LOOP AT gt_swastrtab INTO gs_swastrtab.
          CLEAR gs_html.
          gs_html = gs_swastrtab-str.
          APPEND gs_html TO gt_html.
        ENDLOOP.

        CALL SCREEN 100.
      ENDIF.
      CALL FUNCTION 'FP_JOB_CLOSE'
        EXCEPTIONS
          usage_error    = 1
          system_error   = 2
          internal_error = 3
          OTHERS         = 4.
      IF sy-subrc <> 0.
* Implement suitable error handling here
      ENDIF.
    ENDIF.
  ENDIF.

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'PF_0100'.

  IF main_container IS INITIAL AND p_save = abap_true.
    CREATE OBJECT main_container
      EXPORTING
        container_name              = 'CUST_CONTROL'
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        OTHERS                      = 6.

    CREATE OBJECT html_viewer
      EXPORTING
        parent = main_container
        uiflag = cl_gui_html_viewer=>uiflag_noiemenu.
    IF sy-subrc <> 0.
      "NO PDF viewwer
    ENDIF.

    CALL METHOD html_viewer->load_data(
      EXPORTING
        type                 = 'text'
        subtype              = 'html'
      IMPORTING
        assigned_url         = gv_url
      CHANGING
        data_table           = gt_html
      EXCEPTIONS
        dp_invalid_parameter = 1
        dp_error_general     = 2
        cntl_error           = 3
        OTHERS               = 4 ).
    IF sy-subrc <> 0.
      WRITE:/ 'ERROR: CONTROL->LOAD_DATA'.
      EXIT.
    ENDIF.
*
    html_viewer->show_url(
       EXPORTING
         url                    = gv_url
         in_place               = 'X'
       EXCEPTIONS
         cntl_error             = 1
         cnht_error_not_allowed = 2
         cnht_error_parameter   = 3
         dp_error_general       = 4
            ).

  ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
    WHEN 'EXIT'.
      LEAVE TO SCREEN 0.
    WHEN 'CANCEL'.
      LEAVE TO SCREEN 0.
    WHEN OTHERS.
  ENDCASE.
ENDMODULE.

Screen : 0100

PROCESS BEFORE OUTPUT.
 MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
 MODULE USER_COMMAND_0100.

Screen%20Layout

Screen Layout

 

When we call FP_JOB_CLOSE FM it show in custom container as below type

CALL METHOD html_viewer->load_data(
EXPORTING
type                 APPLICATION
subtype          PDF

 

What we have done here is we extracted BASE64 of PDF and showed it inside HTML page and set below type

CALL METHOD html_viewer->load_data(
EXPORTING
type                 ‘text’
subtype          ‘html’

We can use all below HTML tags to control PDF file display

#toolbar=0&scrollbar=0&navpanes=0&embedded=true&statusbar=0&view=Fit;
readonly=true;disableprint=true;” ” width=”1170″ height=”800″ style=”border:none;

Demo Output

  • Disable Save Button = ABAP_FALSE

  • Disable Save Button = ABAP_TRUE

 

Conclusion

There are types of file we can be open in cl_gui_html_viewer. FP_JOB_CLOSE FM call Adobe Form as PDF file instead of which I have call PDF file inside HTML page and disable toolbar and button’s as per required.

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Aditya Vora
      Aditya Vora

      Very helpful...

      Author's profile photo Makdoomali Sayed
      Makdoomali Sayed

      well written and helpfull