Angular 8可以下载pdf,但不能下载rt文件

问题描述 投票:0回答:1

任何帮助或提示将不胜感激!!我正在使用Angular 8,并且可以使用以下代码下载pdf。但是我不能为rtf做它:

在我的lab-viewer-pdf.component.html中:

            <div style="height: 100vh; width: 100%;">
                <object type="application/rtf" [data]="pdfData | safe" height="100%" width="100%">

                </object>
            </div>

在我的lab-viewer-pdf.component.ts中:

                import { Component, OnInit } from '@angular/core';
            import { environment } from '../../environments/environment';

            @Component({
              selector: 'app-lab-viewer-rtf',
              templateUrl: './lab-viewer-rtf.component.html',
              styleUrls: ['./lab-viewer-rtf.component.css']
            })
            export class LabViewerRTFComponent implements OnInit {

              apiURL: string = environment.baseUrl;
              pdfData: any;
              constructor() { }

              ngOnInit() {
                var work_data = localStorage.getItem("l_id");
                this.pdfData = "data:application/rtf;base64," +  work_data;

              }
            }

在我的home.component.html中:

                selectLab(contentType: string, data) {
                localStorage.setItem("l_id", data);
                //let url = this.apiURL + `/ExtenalSites/FlowLabs/#/LabViewer`
                let url = '';

                if (contentType === 'PDF')
                {
                  url = `/#/LabViewerPDF`;
                }
                else if (contentType === 'RTF')
                {
                  url = `/#/LabViewerRTF`;
                }

                window.open(url);


              }

[当我尝试下载rtf时,我在谷歌浏览器中看到一个插件错误提示。这是我的lab-viewer-rtf.component.html:

<div style="height: 100vh; width: 100%;">
<object type="application/rtf" [data]="pdfData | safe" height="100%" width="100%">

</object>
</div>

这是我的lab-viewer-rtf.component.ts:

                import { Component, OnInit } from '@angular/core';
            import { environment } from '../../environments/environment';

            @Component({
              selector: 'app-lab-viewer-rtf',
              templateUrl: './lab-viewer-rtf.component.html',
              styleUrls: ['./lab-viewer-rtf.component.css']
            })
            export class LabViewerRTFComponent implements OnInit {

              apiURL: string = environment.baseUrl;
              pdfData: any;
              constructor() { }

              ngOnInit() {
                var work_data = localStorage.getItem("l_id");
                this.pdfData = "data:application/rtf;base64," +  work_data;

              }
            }

错误图片:enter image description here

angular rtf
1个回答
0
投票

与浏览器本身支持显示的pdf文档不同,您不能直接从Webbrowser显示rtf文件。用户必须从Web服务器下载rtf文件,并使用适当的软件(MS Word,Open Office)将其打开。为此,必须根据您的网络服务器,将以下标头添加到响应中:

Response.ContentType = "application/octet-stream";
Response.Headers["Content-Transfer-Encoding"] = "Binary";
Response.Headers["Content-disposition"] = "attachment; filename=\"fileName.rtf\"";
© www.soinside.com 2019 - 2024. All rights reserved.