I'm try to adapt pdf.js (complete version) to my needs, I just want to set the initial scale to 'page-fit' whatever the previous scale. So I try to modify viewer.js to achieve this ...
First the DEFAULT_SCALE global (line 27) is ignored, it seems that the initial scale is defined by the loading sequence according to the previous scale.
The document is loaded by the load function (line 832) wich is called below, but the 'scale' argument doesn't set the initial scale ...
load: function pdfViewLoad(pdfDocument, scale) {
...
}
Attempting to set the scale in the firstPagePromise.then ... function (line 903) has no effect either :
firstPagePromise.then(function(pdfPage) {
scale = 'page-fit';
...
}
There's also a PDFView.currentScale property, I have tried to set it in different places but this doesn't affect either :
this.currentScale = 'page-fit';
Finally I can set this scale by calling the setScale function into onePageRendered.then ... function (line 920) :
onePageRendered.then(function () {
PDFView.setScale('page-fit', true);
...
}
It works, but the setScale function is then called twice, because it seems to be called a first time by onePageRendered (I don't know where) with the previous scale (?). This solution make two visible renders and is not really satisfying ...
How can I do that properly please ?
To set default view in 'page-fit' whatever the previous selection, you need to simply change two line in viewer.js file.
var DEFAULT_SCALE_VALUE = 'auto'
to 'page-fit';var DEFAULT_PREFERENCES = {
//if you set false view didn't load view by previous scale. Always load by default scale defined by step 1.
showPreviousViewOnLoad: true to false,
defaultZoomValue: '',
sidebarViewOnLoad: 0,
enableHandToolOnLoad: false,
enableWebGL: false,
pdfBugEnabled: false,
disableRange: false,
disableStream: false,
disableAutoFetch: false,
disableFontFace: false,
disableTextLayer: false,
useOnlyCssZoom: false,
externalLinkTarget: 0,
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With