From 1a7a59cea716fb3a9ee6e6ddc575a15853f1216c Mon Sep 17 00:00:00 2001 From: Michal Kinas <113341662+MichalKinas@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:16:57 +0200 Subject: [PATCH] [MNT-25896] Introduce page rotation button in pdf viewer (#12241) * [MNT-25896] Introduce page rotation button in pdf viewer * [MNT-25896] CR fixes --- .../pdf-viewer/pdf-viewer.component.html | 9 +++++- .../pdf-viewer/pdf-viewer.component.spec.ts | 28 ++++++++++++++++++- .../pdf-viewer/pdf-viewer.component.ts | 18 ++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/core/viewer/pdf/src/lib/components/pdf-viewer/pdf-viewer.component.html b/lib/core/viewer/pdf/src/lib/components/pdf-viewer/pdf-viewer.component.html index 9d88175c4c..e0794193ad 100644 --- a/lib/core/viewer/pdf/src/lib/components/pdf-viewer/pdf-viewer.component.html +++ b/lib/core/viewer/pdf/src/lib/components/pdf-viewer/pdf-viewer.component.html @@ -106,6 +106,14 @@ + + - diff --git a/lib/core/viewer/pdf/src/lib/components/pdf-viewer/pdf-viewer.component.spec.ts b/lib/core/viewer/pdf/src/lib/components/pdf-viewer/pdf-viewer.component.spec.ts index 3bdf41f247..4e712dd1e5 100644 --- a/lib/core/viewer/pdf/src/lib/components/pdf-viewer/pdf-viewer.component.spec.ts +++ b/lib/core/viewer/pdf/src/lib/components/pdf-viewer/pdf-viewer.component.spec.ts @@ -461,8 +461,10 @@ describe('Test PdfViewer - User interaction', () => { let component: PdfViewerComponent; let testingUtils: UnitTestingUtils; let pdfViewerSpy: jasmine.Spy; + let pageViewMock: { width: number; height: number; scale: number; rotation: number; update: jasmine.Spy }; beforeEach(fakeAsync(() => { + pageViewMock = { width: 100, height: 100, scale: 1, rotation: 0, update: jasmine.createSpy() }; pdfViewerSpy = jasmine.createSpy('PDFViewer').and.returnValue({ setDocument: jasmine.createSpy().and.returnValue({ loadingTask: () => ({ @@ -479,7 +481,7 @@ describe('Test PdfViewer - User interaction', () => { update: jasmine.createSpy(), currentScaleValue: 1, _currentPageNumber: 1, - _pages: [{ width: 100, height: 100, scale: 1 }] + _pages: [pageViewMock] }); TestBed.configureTestingModule({ @@ -617,6 +619,30 @@ describe('Test PdfViewer - User interaction', () => { }), 300); }); + describe('Rotation', () => { + it('should rotate only the current page counter-clockwise by 90 degrees', () => { + testingUtils.clickByCSS('#viewer-rotate-page-button'); + + expect(pageViewMock.update).toHaveBeenCalledWith({ rotation: 270 }); + }); + + it('should wrap rotation back to 0 after a full turn', () => { + pageViewMock.rotation = 90; + + testingUtils.clickByCSS('#viewer-rotate-page-button'); + + expect(pageViewMock.update).toHaveBeenCalledWith({ rotation: 0 }); + }); + + it('should recompute the document overflow after rotation', () => { + spyOn(component, 'setDocumentOverflow'); + + testingUtils.clickByCSS('#viewer-rotate-page-button'); + + expect(component.setDocumentOverflow).toHaveBeenCalled(); + }); + }); + describe('Resize interaction', () => { it('should resize event trigger setScaleUpdatePages', () => { spyOn(component, 'onResize'); diff --git a/lib/core/viewer/pdf/src/lib/components/pdf-viewer/pdf-viewer.component.ts b/lib/core/viewer/pdf/src/lib/components/pdf-viewer/pdf-viewer.component.ts index d1a91c5690..6c1c13d97a 100644 --- a/lib/core/viewer/pdf/src/lib/components/pdf-viewer/pdf-viewer.component.ts +++ b/lib/core/viewer/pdf/src/lib/components/pdf-viewer/pdf-viewer.component.ts @@ -577,6 +577,24 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { this.setScaleUpdatePages(newScale); } + /** + * Rotate the currently displayed page 90 degrees counter-clockwise. + * + * Only the current page is affected; every other page keeps its own rotation. + * The angle wraps around, so four consecutive calls return the page to its + * original orientation (0 → 270 → 180 → 90 → 0). The document overflow state + * is recomputed afterwards, since rotation swaps the page width and height. + */ + rotatePage() { + if (this.pdfViewer) { + const pageView = this.pdfViewer._pages[this.pdfViewer._currentPageNumber - 1]; + if (pageView) { + pageView.update({ rotation: (pageView.rotation + 270) % 360 }); + this.setDocumentOverflow(); + } + } + } + /** * load the previous page */