首页 > 解决方案 > 无法在 Chrome 上打开 base64 pdf

问题描述

我在 crhome 和 MS Edge 上打开/查看 base64 pdf 文档时遇到问题。它在 Firefox 上运行良好。我正在使用 Angular 7,我从 DB MySql 获取 pdf 作为 base64 字符串。

这是角度代码:

@Component({
  selector: 'app-show-doc',
  templateUrl: './show-doc.component.html',
  styleUrls: ['./show-doc.component.css']
})
export class ShowDocComponent {
  lead: number;
  linha: number;
  fxNome: string;
  imagePath: Url = null;
  private data: any;
  private fileName: string;
  constructor(private dataService: DataService,
               private route: ActivatedRoute,
               private _sanitizer: DomSanitizer ) {

    this.route.paramMap.subscribe(
      param => {
        this.lead = +param.get('lead');
        this.linha = +param.get('linha');
        this.dataService.getData('doc/' + this.lead + '/' + this.linha).subscribe(
          (resp: any) => {
            const document = resp.json()[0];
            this.fxNome = document.nomedoc;
            this.imagePath = this._sanitizer.bypassSecurityTrustResourceUrl('data:application/pdf;base64,' + document.fx64);
          }
        );
      }
    );
}

}

在html中: <object [data]="imagePath" style="width:1100px;height:800px;"></object>

标签: angularpdfviewbase64

解决方案


推荐阅读