Skip to content

Commit

Permalink
Merge pull request #1146 from shamoon/fix-1145
Browse files Browse the repository at this point in the history
Fix: use page init for first updateSize
  • Loading branch information
VadimDez authored Oct 31, 2024
2 parents 0391841 + 5355725 commit 5323a9a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/app/pdf-viewer/pdf-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,9 @@ export class PdfViewerComponent
stickToPage = !this._stickToPage;
}

// 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 })
});
this.pdfViewer.currentScale = scale;
if (stickToPage)
this.pdfViewer.scrollPageIntoView({ pageNumber: page.pageNumber, ignoreDestinationZoom: true })
}
});
}
Expand Down Expand Up @@ -573,7 +570,15 @@ export class PdfViewerComponent
});
}

this.updateSize();
if (!this.pdfViewer._pages?.length) {
// the first time we wait until pages init
const sub = this.pageInitialized.subscribe(() => {
this.updateSize();
sub.unsubscribe();
})
} else {
this.updateSize();
}
}

private getScale(viewportWidth: number, viewportHeight: number) {
Expand Down

0 comments on commit 5323a9a

Please sign in to comment.