Restrict zoom percentage on mobile devices
11 Feb 20266 minutes to read
Use minZoom and maxZoom to restrict zoom levels on mobile devices and improve scrolling performance and perceived load time. Restricting zoom prevents extreme zoom levels that can degrade rendering performance on constrained devices.
import { Component, OnInit } from '@angular/core';
import { LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
TextSearchService, AnnotationService, TextSelectionService,
PrintService, FormFieldsService, FormDesignerService,
PageOrganizerService } from '@syncfusion/ej2-angular-pdfviewer';
import {Browser} from '@syncfusion/ej2-base';
@Component({
selector: 'app-container',
// specifies the template string for the PDF Viewer component
template: `<div class="content-wrapper">
<ejs-pdfviewer id="pdfViewer"
[documentPath]='document'
[resourceUrl] = 'resource'
(documentLoad)='documentLoaded($event)'
style="height:640px;display:block">
</ejs-pdfviewer>
</div>`,
providers: [ LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
AnnotationService, TextSearchService, TextSelectionService,
PrintService, FormFieldsService, FormDesignerService, PageOrganizerService]
})
export class AppComponent implements OnInit {
public document: string = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
public resource: string = "https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2-pdfviewer-lib";
ngOnInit(): void {
}
documentLoaded(e: any): void {
var viewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0];
if (Browser.isDevice && !viewer.enableDesktopMode) {
viewer.maxZoom = 200;
viewer.minZoom = 10;
}
else {
viewer.zoomMode = 'Default';
}
}
}import { Component, OnInit } from '@angular/core';
import { LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
TextSearchService, AnnotationService, TextSelectionService,
PrintService, FormFieldsService, FormDesignerService,
PageOrganizerService } from '@syncfusion/ej2-angular-pdfviewer';
import {Browser} from '@syncfusion/ej2-base';
@Component({
selector: 'app-container',
// specifies the template string for the PDF Viewer component
template: `<div class="content-wrapper">
<ejs-pdfviewer id="pdfViewer"
[serviceUrl]='service'
[documentPath]='document'
(documentLoad)='documentLoaded($event)'
style="height:640px;display:block">
</ejs-pdfviewer>
</div>`,
providers: [ LinkAnnotationService, BookmarkViewService, MagnificationService,
ThumbnailViewService, ToolbarService, NavigationService,
AnnotationService, TextSearchService, TextSelectionService,
PrintService, FormFieldsService, FormDesignerService, PageOrganizerService]
})
export class AppComponent implements OnInit {
public service = 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer';
public document = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
ngOnInit(): void {
}
documentLoaded(e: any): void {
var viewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0];
if (Browser.isDevice && !viewer.enableDesktopMode) {
viewer.maxZoom = 200;
viewer.minZoom = 10;
}
else {
viewer.zoomMode = 'Default';
}
}
}By implementing this, you ensure that the maximum zoom percentage on mobile devices is limited to 200% and the minimum zoom percentage is set to 10%. This prevents performance issues that may arise from excessive zooming on mobile platforms.