首页 > 解决方案 > 可以下载时 PDFViewer 不显示内容

问题描述

我正在尝试在 SAPUI5 应用程序中使用PDFViewer,类似于以下示例应用程序

当我尝试在 Google chrome 中使用这个组件时,它不会加载数据,但是可以下载 PDF 本身,它显示 url 有效并且文件可用。

镀铬

如果我在 Firefox 或 IE 中打开它,它可以工作!

火狐

标签: sapui5abapdms

解决方案


我在这里与 SAP OpenUI5 团队讨论了这个问题。最后我们明白问题不在于 UI5 库,问题出在我们的 ABAP 实现内部,该实现提供了来自 SAP Document Management System (SAP DMS) 的 PDF 文件的下载链接。

我们终于找到了解决方案,并发现了为什么我们尝试从 SAP DMS 显示的 pdf 是可下载的,而现代浏览器(如 Chrome 或 Firefox)的 pdf 查看器中却没有显示它。

解决方案的来源可以在这里找到。

以下两个更改与互联网上大多数教程中可以找到的正常实现不同:

  1. 标头值必须更改为Inline;filename=而不是outline;filename.
  2. 调用该方法/IWBEP/IF_MGW_CONV_SRV_RUNTIME=>Set_header设置标题。

最后,我们在 SAP 系统中有以下 ABAP 代码,用于从文档管理系统 (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.


推荐阅读