Skip to content

Commit

Permalink
#2120 stop firing (pdfLoaded) twice when [src] fires; refactored …
Browse files Browse the repository at this point in the history
…`scrollSignatureWarningIntoView()`
  • Loading branch information
stephanrauh committed Mar 10, 2024
1 parent 148097b commit 2e34852
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions projects/ngx-extended-pdf-viewer/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,4 @@
- 19.4.0-alpha.1 #2148 update the buttons then the annotation editor mode changes programmatically; add typing the the editor modes
- 19.4.0-alpha.2 #2148 allow to pass both native pdf.js coordinate and percentages to `NgxExtendedePdfViewerService.addImageToAnnotationLayer()`
- 19.4.0 #2180 improve CSP (content security policy) support; allow to pass pixels to `NgxExtendedePdfViewerService.addImageToAnnotationLayer()`; #2179 restrict the file open dialog to PDF files; #2168 split the `<pdf-rotate-page>` into `<pdf-rotate-page-cw>` and `<pdf-rotate-page-ccw>`
- 19.4.1 #2120 stop firing `(pdfLoaded)` twice when `[src]` fires; refactored `scrollSignatureWarningIntoView()`
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,7 @@ export class NgxExtendedPdfViewerComponent implements OnInit, AfterViewInit, OnC
this.page = pages;
}
this.scrollSignatureWarningIntoView(pdfLoadedEvent.source.pdfDocument);
this.pdfLoaded.emit({ pagesCount: pdfLoadedEvent.source.pdfDocument?.numPages } as PdfLoadedEvent);
if (this.findbarVisible) {
PDFViewerApplication.findBar.open();
}
Expand Down Expand Up @@ -1968,7 +1969,6 @@ export class NgxExtendedPdfViewerComponent implements OnInit, AfterViewInit, OnC
}
options.rangeChunkSize = pdfDefaultOptions.rangeChunkSize;
await PDFViewerApplication.open(options);
this.pdfLoaded.emit({ pagesCount: PDFViewerApplication.pagesCount });
} catch (error) {
this.pdfLoadingFailed.emit(error);
}
Expand Down Expand Up @@ -2424,19 +2424,20 @@ export class NgxExtendedPdfViewerComponent implements OnInit, AfterViewInit, OnC
const page = await pdf.getPage(i);
const annotations = await page.getAnnotations();

annotations.forEach((a) => {
if (a.fieldType === 'Sig') {
this.ngZone.run(() => {
this.hasSignature = true;
setTimeout(() => {
const viewerContainer = document.querySelector('#viewerContainer') as HTMLElement;
viewerContainer.scrollBy(0, -32);
});
// Check if there is at least one 'Sig' fieldType in annotations
this.hasSignature = annotations.some((a) => a.fieldType === 'Sig');

if (this.hasSignature) {
this.ngZone.run(() => {
// Defer scrolling to ensure it happens after any other UI updates
setTimeout(() => {
const viewerContainer = document.querySelector('#viewerContainer');
viewerContainer?.scrollBy(0, -32); // Adjust the scroll position
});
}
});
});
break; // stop looping through the pages as soon as we find a signature
}
}
this.pdfLoaded.emit({ pagesCount: pdf?.numPages } as PdfLoadedEvent);
}

public async zoomToPageWidth(event: MouseEvent): Promise<void> {
Expand Down

0 comments on commit 2e34852

Please sign in to comment.