小编ILY*_*021的帖子

无法在 Angular 10 中的“pdf-viewer”=>“ng2-pdf-viewer”中显示 blob url

我有一个 API,它将上传的文件作为 blob 返回。当我尝试绑定srcblob URL 时,它不会显示任何内容,但是,当我尝试绑定直接 URL 时,它可以显示 PDF 文件。这是我下面给出的代码。
我的 TS 代码

downloadFile(fileData: Fileuploader) {
        this.tempBlob= null;
        
        //Fetching Data File 
        this.apiservice.getDownloadfile(fileData).subscribe(
            (retFileData: any) => {
                this.tempRetFileData = retFileData;
                this.tempBlob = new Blob([retFileData], { type: this.contentType });                    
            },
            (err: Error) => {
                
            },
            () => {                             
                const blob: Blob = new Blob([this.tempBlob], { type: this.contentType });       
                const fileName: string ='ilvsna.pdf';
                this.myBlobURL = URL.createObjectURL(blob);
            }
        );
    }
Run Code Online (Sandbox Code Playgroud)

超文本标记语言

 <pdf-viewer [src]="myBlobURL"
              [render-text]="true"
              [original-size]="false"
              style="width: 400px; height: 500px"
  ></pdf-viewer>
Run Code Online (Sandbox Code Playgroud)

注意:如果我将 …

html pdf api typescript angular

3
推荐指数
1
解决办法
8188
查看次数

标签 统计

angular ×1

api ×1

html ×1

pdf ×1

typescript ×1