当在外部窗口中打开pdf时,我有一个事件问题。即使使用'viewerId‘属性,也不会触发它们。下面是我的代码:
HTML
<a *ngIf="document.s3_link" class="document-title" (click)="openDocument(document)">{{ document.description }}</a
>
<ng2-pdfjs-viewer
#externalPdfViewer
viewerId="MyUniqueID"
[externalWindow]="true"
(onDocumentLoad)="highlightSearchTerm()"
></ng2-pdfjs-viewer>TypeScript
openDocument(document): void {
this.getDocumentBlob(document.s3_link).subscribe(res => {
this.externalPdfViewer.pdfSrc = res
this.externalPdfViewer.downloadFileName = document.description
this.externalPdfViewer.refresh()
})
}
getDocumentBlob(link): Observable<any> {
let headers = new HttpHeaders()
headers = headers.set("Accept", "application/pdf")
return this.http.get(link, { headers: headers, responseType: "blob" })
}
highlightSearchTerm() {
this.externalPdfViewer.PDFViewerApplication.findController.executeCommand(
"find",
{
caseSensitive: false,
findPrevious: undefined,
highlightAll: true,
phraseSearch: true,
query: this.initQuery,
}
)
}发布于 2019-11-16 03:27:37
在其中一个问题的文档中找到了这一点。
在新窗口中打开PDF时,无法将事件发送回以前的窗口。
请按如下方式查看:Communication between tabs or windows
需要更新文档以反映这一点。使用上面的技术,它可以实现,但这需要改进/实现。
https://stackoverflow.com/questions/58288928
复制相似问题