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 ?
The solution is here, thank you Snuffleupagus :
Since the initial scale could be set in a number of ways (from the browser history, by a preference, by the view history or by specifying the scale with a hash parameter), I think that the only way to always force a particular scale on load would something along these lines:
- Change
DEFAULT_SCALE
to what you want: https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L27.- Replace: https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L1117-L1121, with:
this.setScale(DEFAULT_SCALE, true);