我使用ngx-extended-pdf-viewer ( npm )来呈现PDF,当我直接设置path+fileName时,它可以工作,如下所示:
<ngx-extended-pdf-viewer [src]="'assets/example.pdf'"
[showPrintButton]="false" [showBookmarkButton]="false"
[showOpenFileButton]="false"
[showSidebarOnLoad]="false"
[showSidebarButton]="true"
delayFirstView="6000" useBrowserLocale="false">
</ngx-extended-pdf-viewer>我希望在.TS中创建一个变量,并将其绑定到src中,如下所示:
类型标
...
ngOnInit() {
this.filePathAndName = "'assets/example.pdf'";
... <ngx-extended-pdf-viewer [src]="{{filePathAndName}}"
[showPrintButton]="false" [showBookmarkButton]="false"
[showOpenFileButton]="false"
[showSidebarOnLoad]="false"
[showSidebarButton]="true"
delayFirstView="6000" useBrowserLocale="false">
</ngx-extended-pdf-viewer>但不起作用。
主要问题是src需要有两个符号:引号(“)后面跟着Apostrophe (‘).”“path+name”(没有空格)
我的问题是:如何在类型记录中的变量中放入一个有效值,以便在这个特定的场景中正确地呈现?
发布于 2019-03-19 22:28:40
它不需要那些引号。它们仅用于文字字符串绑定。试试这个:
this.filePathAndName = "assets/example.pdf";
<ngx-extended-pdf-viewer *ngIf="filePathAndName" [src]="filePathAndName" 发布于 2019-07-10 14:52:45
可能要晚了才回复,对以后的人会有帮助。
HTML代码:
<ngx-extended-pdf-viewer *ngIf="currentPdf"
[src]="currentPdf" useBrowserLocale="false"
style="height: 100%; width: 100%"
[delayFirstView]="1000"
[showHandToolButton]="true"
[handTool] = false>
</ngx-extended-pdf-viewer>打字本代码:
public currentPdf: string
displayPdf() {
// setTimeout(() => {
this.service.getPdfExtractedContent(this.id)
.pipe(first())
.subscribe(
data => {
this.currentPdf = URL.createObjectURL(this.b64toBlob(data.ExtractedByte,'data:application/pdf;base64', 1024));
},
error => {
console.log(error);
}
);
// }, 500);
}
b64toBlob(b64Data, contentType, sliceSize) {
const byteCharacters = atob(b64Data);
const byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize);
const byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
const blob = new Blob(byteArrays, {type: contentType});
return blob;
}https://stackoverflow.com/questions/55250786
复制相似问题