intbot / ng2-pdfjs-viewer

An angular component for PDFJS and ViewerJS (Supports all versions of angular)
Apache License 2.0
225 stars 113 forks source link

OnAfterPrint event not triggered when printing with custom button #187

Closed crabouif closed 2 years ago

crabouif commented 2 years ago

Hy,

I want to start printing of PDF document from an own button (stylized). So for that I hidden the default print button in tool bar [print]="false" and I start manually the printing with my button by reloading PDF with startPrint option:

<div class="pdf-viewer">
    <ng2-pdfjs-viewer #pdfViewer
                      [locale]="locale"
                      [viewBookmark]="false"
                      [openFile]="false"
                      [fullScreen]="false"
                      [print]="false">
    </ng2-pdfjs-viewer>
</div>
    @ViewChild('pdfViewer') pdfViewer!: PdfJsViewerComponent;

    ngAfterViewInit(): void {
        this.pdfViewer.onAfterPrint.subscribe(() => {
            // Here my code...
        });
    }

    print() {
        this.pdfViewer.startPrint = true;
        this.pdfViewer.refresh();
    }

But in this case, the onAfterPrint event is not triggered. Do you hanve any idea ?

Thanks a lot for great job !

crabouif commented 2 years ago

Sorry I found my self mistake: As described in your demo, I just added the viewerId and it works.

<div class="pdf-viewer">
    <ng2-pdfjs-viewer #pdfViewer
                      [locale]="locale"
                      [viewBookmark]="false"
                      viewerId="MyUniqueID"
                      [openFile]="false"
                      [fullScreen]="false"
                      (onAfterPrint)="onAfterPrint($event)"
                      [print]="true">
    </ng2-pdfjs-viewer>
</div>