diff --git a/src/app/pdf-viewer/pdf-viewer.component.spec.ts b/src/app/pdf-viewer/pdf-viewer.component.spec.ts index 7757a46d3..9ced71168 100644 --- a/src/app/pdf-viewer/pdf-viewer.component.spec.ts +++ b/src/app/pdf-viewer/pdf-viewer.component.spec.ts @@ -71,11 +71,10 @@ describe('AppComponent', () => { }); describe('getScale', () => { - it('should get scale 1 with viewportWidth = 0 or viewerContainerWidth = 0', function() { - pdfViewerFixture.detectChanges(); + it('should get scale 1 with offsetWidth = 0', function () { let spy = spyOnProperty( - (pdfViewer as any).pdfViewerContainer.nativeElement, - 'clientWidth', + (pdfViewer as any).element.nativeElement, + 'offsetWidth', 'get' ).and.returnValue(0); diff --git a/src/app/pdf-viewer/pdf-viewer.component.ts b/src/app/pdf-viewer/pdf-viewer.component.ts index acce8400e..0ea6c6c95 100644 --- a/src/app/pdf-viewer/pdf-viewer.component.ts +++ b/src/app/pdf-viewer/pdf-viewer.component.ts @@ -344,11 +344,10 @@ export class PdfViewerComponent .getPage(currentViewer.currentPageNumber) .then((page: PDFPageProxy) => { const rotation = this._rotation || page.rotate; - const viewportWidth = - (page as any).getViewport({ - scale: this._zoom, - rotation - }).width * PdfViewerComponent.CSS_UNITS; + const viewport = (page as any).getViewport({ + scale: this._zoom, + rotation + }); let scale = this._zoom; let stickToPage = true; @@ -356,11 +355,10 @@ export class PdfViewerComponent if ( !this._originalSize || (this._fitToPage && - viewportWidth > this.pdfViewerContainer.nativeElement.clientWidth) + viewport.width > this.element.nativeElement.offsetWidth) ) { scale = this.getScale( - (page as any).getViewport({ scale: 1, rotation }) - .width + (page as any).getViewport({ scale: 1, rotation }).width ); stickToPage = !this._stickToPage; } @@ -590,16 +588,16 @@ export class PdfViewerComponent } private getScale(viewportWidth: number) { - const pdfContainerWidth = - this.pdfViewerContainer.nativeElement.clientWidth - + const offsetWidth = + this.element.nativeElement.offsetWidth - (this._showBorders ? 2 * PdfViewerComponent.BORDER_WIDTH : 0); - if (pdfContainerWidth === 0 || viewportWidth === 0) { + if (offsetWidth === 0) { return 1; } return ( - (this._zoom * (pdfContainerWidth / viewportWidth)) / + (this._zoom * (offsetWidth / viewportWidth)) / PdfViewerComponent.CSS_UNITS ); }