How do set Magnification in PDF Document using JavaScript

Hello team,

We are Evaluating PDFTron into our Salesforce Application.
I need one help how to set Magnification in Initial Tab of the PDF Document properties.
We are using JavaScript to do this.
We could able to set Navigation tab value and Page layout value using below code.

const doc = docViewer.getDocument();
const pdfDoc = await doc.getPDFDoc();
const pref = await pdfDoc.getViewPrefs();
const updateddata = pref.setLayoutMode(
PDFNet.PDFDocViewPrefs.PageLayout.e_TwoColumnLeft
);

doc.getBookmarks().then((bookmarks) => {
if (bookmarks.length > 0) {
pref.setPageMode(PDFNet.PDFDocViewPrefs.PageMode.e_UseBookmarks);
} else {
pref.setPageMode(PDFNet.PDFDocViewPrefs.PageMode.e_UseNone);
} });

I have uploaded one image that could help you to understand the issue.

Please help me to find the solution for the issue.


Thanks
Vijaykumar

The PDF viewer preferences are not a very reliable feature of the PDF standard, as many viewers do not support them, or if they do, they also allow users to block them anyway (since often users don’t want their settings to change).

To best answer you it would be important to better understand your requirements.

Evaluating PDFTron into our Salesforce Application.

Are you evaluating our WebViewer product (full viewing experience)? Or just our PDF SDK?

We are using JavaScript to do this.

Are you running this javascript code client side in the Salesforce site? Or on your own server using NodeJS?

We could able to set Navigation tab value and Page layout value using below code.

Why is setting the navigation and page layout mode viewer preferences in the PDF file itself important for you?
If you are using WebViewer, you can control all this from the WebViewer UI/UX.
Or are you trying to support other PDF viewers? If so which exactly?

Hi Ryan
Thank you for your replay.

We are using complete WebViewer product into our salesforce application.
I am running Javascript code in client side in the Salesforce site.

My requirement is, I am reading one pdf document from my local system and I am updating some PDF Properties and save into my local system. To do this I am using PDFNet.PDFDoc APIs.

Is it possible to set Magnification using PDFNet.PDFDoc? or it will allow only in WebViewer UI/UX?.

Thanks,
Vijaykumar

Is it possible to set Magnification using PDFNet.PDFDoc

The issue is that the PDF specification itself does not allow you to specify a specific zoom level. The closest are ViewArea, ViewClip or FitWindow, though note that the first two are officially deprecated. Regardless, many PDF readers/viewers do not check these settings anyway, so their usefulness is dubious.

or it will allow only in WebViewer UI/UX?.

The only PDF reader/viewer you have control over is your WebViewer instance. You cannot force anything across all PDF viewers/readers via this sort of PDF metadata.

If the above does not answer your question, please elaborate why controlling the “Magnification” is important for you?
What about your users who may not want the magnification controlled?