Skip to content

Commit

Permalink
Merge pull request #1098 from ftaffelt/fix-#1097
Browse files Browse the repository at this point in the history
Fix #1097: delay scale and scroll ops until the viewer has the pages initialized
  • Loading branch information
VadimDez committed May 16, 2024
2 parents 4f343ac + 0918e37 commit 9ea7afd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/app/pdf-viewer/pdf-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,14 @@ export class PdfViewerComponent
from(
this._pdf!.getPage(
this.pdfViewer.currentPageNumber
) as unknown as Promise<PDFPageProxy>
)
)
.pipe(takeUntil(this.destroy$))
.subscribe({
next: (page: PDFPageProxy) => {
const rotation = this._rotation + page.rotate;
const viewportWidth =
(page as any).getViewport({
page.getViewport({
scale: this._zoom,
rotation
}).width * PdfViewerComponent.CSS_UNITS;
Expand All @@ -330,13 +330,17 @@ export class PdfViewerComponent
(this._fitToPage &&
viewportWidth > this.pdfViewerContainer.nativeElement.clientWidth)
) {
const viewPort = (page as any).getViewport({ scale: 1, rotation });
const viewPort = page.getViewport({ scale: 1, rotation });
scale = this.getScale(viewPort.width, viewPort.height);
stickToPage = !this._stickToPage;
}

this.pdfViewer.currentScale = scale;
if (stickToPage) this.pdfViewer.scrollPageIntoView({ pageNumber: page.pageNumber, ignoreDestinationZoom: true })
// delay to ensure that pages are ready
this.pdfViewer.pagesPromise?.then(() => {
this.pdfViewer.currentScale = scale;
if (stickToPage)
this.pdfViewer.scrollPageIntoView({ pageNumber: page.pageNumber, ignoreDestinationZoom: true })
});
}
});
}
Expand Down

0 comments on commit 9ea7afd

Please sign in to comment.