Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Persistent pdf-viewer zoom level #876

Open
wants to merge 2 commits into
base: 8.0.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/app/common/pdf-viewer/pdf-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {AlertService} from '../services/alert.service';
styleUrls: ['./pdf-viewer.component.scss'],
})
export class fPdfViewerComponent implements OnDestroy, OnChanges, AfterViewInit {
private readonly ZOOM_MIN = 0.5;
private readonly ZOOM_MAX = 2.5;

private _pdfUrl: string;
public pdfBlobUrl: string;
public useNativePdfViewer = false;
Expand All @@ -43,6 +46,9 @@ export class fPdfViewerComponent implements OnDestroy, OnChanges, AfterViewInit

ngAfterViewInit(): void {
this.useNativePdfViewer = localStorage.getItem('useNativePdfViewer') === 'true';
const storedZoomValue = parseFloat(localStorage.getItem('pdfViewerZoom')) || 1;
// Clamp zoom value between ZOOM_MIN and ZOOM_MAX
this.zoomValue = Math.min(Math.max(storedZoomValue, this.ZOOM_MIN), this.ZOOM_MAX);
}

ngOnChanges(changes: SimpleChanges): void {
Expand Down Expand Up @@ -76,13 +82,15 @@ export class fPdfViewerComponent implements OnDestroy, OnChanges, AfterViewInit
}

public zoomIn() {
if (this.zoomValue < 2.5) {
if (this.zoomValue < this.ZOOM_MAX) {
this.zoomValue += 0.1;
localStorage.setItem('pdfViewerZoom', this.zoomValue.toString());
}
}
public zoomOut() {
if (this.zoomValue > 0.5) {
if (this.zoomValue > this.ZOOM_MIN) {
this.zoomValue -= 0.1;
localStorage.setItem('pdfViewerZoom', this.zoomValue.toString());
}
}

Expand Down