0

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

打字稿

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,
            }
        )
    }
4

1 回答 1

1

Found this in documentation in one of the issues.

When you are opening PDF in a new window, events cannot be emitted back to former window.

Please see this SO: Communication between tabs or windows

Documentation needs to be updated to reflect this. Using above techniques, it may be achieved, but that would require an improvement/implementation.

于 2019-11-15T19:27:37.120 回答