1

I am trying to use a PDFViewer in a SAPUI5 application, something like the following sample app.

When I try to use this component in Google chrome it will not load the data, however it is possible to download the PDF itself and it shows the url works and file is available.

in chrome

If I open it in Firefox or IE it works!

firefox

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
MJBZA
  • 4,796
  • 8
  • 48
  • 97
  • I'm on Chrome v85.0.4183 and the sample works fine. Have you checked in your network tab that no extension or proxy is blocking the PDF ? – Lumpenstein Sep 08 '20 at 12:12
  • Good point! I opened the link in a new instance of Chrome, and it could be loaded! However, I have deactivated all the extensions and still it is not loadable in my main instance! – MJBZA Sep 08 '20 at 12:33
  • Does the http request to get the pdf content resolve successfully ? Could you provide a reproducable example on Plunkr/JSBin or somewhere else ? – Lumpenstein Sep 08 '20 at 13:21
  • I use exactly the sample of SAP. It seems it is failed because some kind of settings in my google chrome. – MJBZA Sep 08 '20 at 14:56

1 Answers1

3

I discussed the problem here with SAP OpenUI5 team. Finally we understood the problem is not the UI5 library and the problem is inside of our ABAP implementation that provides download link for the PDF file from SAP Document Management System (SAP DMS).

We finally found the solution and discovered why the pdf that we try to show from our SAP DMS is downloadable while it is not shown in the pdf viewer inside the modern browsers like Chrome or Firefox.

The source for the solution can find here.

The below two changes are different from normal implementation that can be found in most of the tutorials in the internet:

  1. The header value must be changed to Inline;filename= instead of outline;filename.
  2. Call the method /IWBEP/IF_MGW_CONV_SRV_RUNTIME=>Set_header to set the header.

Finally we have the following ABAP code in SAP systems for downloading files form document management system (SAP DMS).

"Logic for Download the files from Document Managmenet System
    DATA: ls_lheader TYPE ihttpnvp,
          ls_stream  TYPE ty_s_media_resource,
          ls_entity  TYPE zgw_odata_document_file.

    CONSTANTS: lc_headername  TYPE string VALUE 'Content-Disposition',
               lc_headervalue1 TYPE string VALUE 'inline; filename="',
               lc_headervalue2 TYPE string VALUE '";'.

*    "Get the name of the Entity
    DATA(lv_entity_name) = io_tech_request_context->get_entity_type_name( ).

    CASE lv_entity_name.

      WHEN 'DocumentFile'.
        DATA(lo_document_file) = NEW zcl_gw_odata_document_file( ).
        lo_document_file->read_stream(
          EXPORTING
            it_key_tab = it_key_tab
          IMPORTING
            es_stream  = ls_entity ).

        ls_lheader-name = lc_headername.
        ls_entity-file_name = escape( val = ls_entity-file_name format = cl_abap_format=>e_url ).
        ls_lheader-value = lc_headervalue1 && ls_entity-file_name && lc_headervalue2 .
        set_header( is_header = ls_lheader ).

        ls_stream-mime_type = ls_entity-mimetype.
        ls_stream-value = ls_entity-binfile.
        copy_data_to_ref( EXPORTING is_data = ls_stream
                          CHANGING  cr_data = er_stream ).
      WHEN OTHERS.
    ENDCASE.

MJBZA
  • 4,796
  • 8
  • 48
  • 97