Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pdf.js : how to properly set the initial scale?

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 ?

like image 810
jeum Avatar asked Feb 01 '14 15:02

jeum


1 Answers

To set default view in 'page-fit' whatever the previous selection, you need to simply change two line in viewer.js file.

  • Step 1: change var DEFAULT_SCALE_VALUE = 'auto' to 'page-fit';
  • Step 2: change DEFAULT_PREFERENCES object 'showPreviousViewOnLoad' property value:
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,
};
like image 130
Mohammad tanvirul islam Avatar answered Oct 13 '22 03:10

Mohammad tanvirul islam