在外部窗口中打开pdf时不会触发事件

时间:2019-10-08 14:53:50

标签: javascript angular ng2-pdfjs-viewer

在外部窗口中打开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,
            }
        )
    }

1 个答案:

答案 0 :(得分:1)

在其中一个问题的文档中找到了这一点。

在新窗口中打开PDF时,无法将事件发回到前一个窗口。

请参阅以下内容:Communication between tabs or windows

文档需要更新以反映这一点。使用上述技术可以实现,但是需要改进/实现。