angular - 无法在 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>
解决方案
推荐阅读
- r - 官员 r 包用于创建具有并排内容的幻灯片 - 内容仅出现在一个部分中
- android - 使用 android EncryptedSharedPreference 的最低 API 级别?
- uikit - 使自定义 SwiftUI 视图适应内置修饰符
- java - 密码和用户名存储在 Apache Ignite 中的什么位置?
- c# - HTMLAgilityPack InnerHTML,解析错误错误
- flutter - 如何解决 OS 错误:Permission denied, errno = 13 in flutter
- java - 在同一个项目中跨多个模块重用测试类
- blazor - Blazor:如何将 ViewModel 从子组件传递到父组件,反之亦然
- pseudocode - 如何找到乘以 i 的语句的时间复杂度
- python - 如何动态且独立地移动 pandas DataFrame 中的列?