问题描述
我正在尝试在SAPUI5应用程序中使用PDFViewer,类似于以下的sample app。
当我尝试在Google chrome中使用此组件时,它不会加载数据,但是可以下载PDF本身,并且它显示url的作品和文件可用。
如果我在Firefox或IE中打开它,就可以了!
解决方法
我与SAP OpenUI5团队讨论了问题here。最终,我们了解到问题不是UI5库,而是问题出在我们的ABAP实现中,该实现提供了SAP文档管理系统(SAP DMS)中PDF文件的下载链接。
我们终于找到了解决方案,并发现了为什么我们尝试从SAP DMS显示的pdf可以下载,而在现代浏览器(如Chrome或Firefox)中的pdf查看器中却没有显示。
解决方案的来源可以找到here。
以下两个更改与正常实现不同,后者可以在Internet上的大多数教程中找到:
- 标头值必须更改为
Inline;filename=
,而不是outline;filename
。 - 调用方法
/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.