Petro Prokopovych
Petro Prokopovych

Reputation: 1

Events are not triggered when open pdf in external window

I have a problem with events, when open pdf in external window. They are not triggered even with 'viewerId' attribute. Here is my code:

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

Upvotes: 0

Views: 976

Answers (1)

James
James

Reputation: 169

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.

Upvotes: 1

Related Questions