pdf_viewer.js 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741
  1. /* Copyright 2014 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /* jshint globalstrict: false */
  16. /* umdutils ignore */
  17. (function (root, factory) {
  18. 'use strict';
  19. if (typeof define === 'function' && define.amd) {
  20. define('pdfjs-dist/web/pdf.components', ['exports', 'pdfjs-dist/build/pdf'],
  21. factory);
  22. } else if (typeof exports !== 'undefined') {
  23. factory(exports, require('../build/pdf.js'));
  24. } else {
  25. factory((root.pdfjsDistWebPDFComponents = {}), root.pdfjsDistBuildPdf);
  26. }
  27. }(this, function (exports, pdfjsLib) {
  28. 'use strict';
  29. var pdfViewerLibs = {
  30. pdfjsWebPDFJS: pdfjsLib
  31. };
  32. (function () {
  33. (function (root, factory) {
  34. {
  35. factory((root.pdfjsWebPDFHistory = {}));
  36. }
  37. }(this, function (exports) {
  38. function PDFHistory(options) {
  39. this.linkService = options.linkService;
  40. this.initialized = false;
  41. this.initialDestination = null;
  42. this.initialBookmark = null;
  43. }
  44. PDFHistory.prototype = {
  45. /**
  46. * @param {string} fingerprint
  47. * @param {IPDFLinkService} linkService
  48. */
  49. initialize: function pdfHistoryInitialize(fingerprint) {
  50. this.initialized = true;
  51. this.reInitialized = false;
  52. this.allowHashChange = true;
  53. this.historyUnlocked = true;
  54. this.isViewerInPresentationMode = false;
  55. this.previousHash = window.location.hash.substring(1);
  56. this.currentBookmark = '';
  57. this.currentPage = 0;
  58. this.updatePreviousBookmark = false;
  59. this.previousBookmark = '';
  60. this.previousPage = 0;
  61. this.nextHashParam = '';
  62. this.fingerprint = fingerprint;
  63. this.currentUid = this.uid = 0;
  64. this.current = {};
  65. var state = window.history.state;
  66. if (this._isStateObjectDefined(state)) {
  67. // This corresponds to navigating back to the document
  68. // from another page in the browser history.
  69. if (state.target.dest) {
  70. this.initialDestination = state.target.dest;
  71. } else {
  72. this.initialBookmark = state.target.hash;
  73. }
  74. this.currentUid = state.uid;
  75. this.uid = state.uid + 1;
  76. this.current = state.target;
  77. } else {
  78. // This corresponds to the loading of a new document.
  79. if (state && state.fingerprint &&
  80. this.fingerprint !== state.fingerprint) {
  81. // Reinitialize the browsing history when a new document
  82. // is opened in the web viewer.
  83. this.reInitialized = true;
  84. }
  85. this._pushOrReplaceState({fingerprint: this.fingerprint}, true);
  86. }
  87. var self = this;
  88. window.addEventListener('popstate', function pdfHistoryPopstate(evt) {
  89. if (!self.historyUnlocked) {
  90. return;
  91. }
  92. if (evt.state) {
  93. // Move back/forward in the history.
  94. self._goTo(evt.state);
  95. return;
  96. }
  97. // If the state is not set, then the user tried to navigate to a
  98. // different hash by manually editing the URL and pressing Enter, or by
  99. // clicking on an in-page link (e.g. the "current view" link).
  100. // Save the current view state to the browser history.
  101. // Note: In Firefox, history.null could also be null after an in-page
  102. // navigation to the same URL, and without dispatching the popstate
  103. // event: https://bugzilla.mozilla.org/show_bug.cgi?id=1183881
  104. if (self.uid === 0) {
  105. // Replace the previous state if it was not explicitly set.
  106. var previousParams = (self.previousHash && self.currentBookmark &&
  107. self.previousHash !== self.currentBookmark) ?
  108. {hash: self.currentBookmark, page: self.currentPage} :
  109. {page: 1};
  110. replacePreviousHistoryState(previousParams, function() {
  111. updateHistoryWithCurrentHash();
  112. });
  113. } else {
  114. updateHistoryWithCurrentHash();
  115. }
  116. }, false);
  117. function updateHistoryWithCurrentHash() {
  118. self.previousHash = window.location.hash.slice(1);
  119. self._pushToHistory({hash: self.previousHash}, false, true);
  120. self._updatePreviousBookmark();
  121. }
  122. function replacePreviousHistoryState(params, callback) {
  123. // To modify the previous history entry, the following happens:
  124. // 1. history.back()
  125. // 2. _pushToHistory, which calls history.replaceState( ... )
  126. // 3. history.forward()
  127. // Because a navigation via the history API does not immediately update
  128. // the history state, the popstate event is used for synchronization.
  129. self.historyUnlocked = false;
  130. // Suppress the hashchange event to avoid side effects caused by
  131. // navigating back and forward.
  132. self.allowHashChange = false;
  133. window.addEventListener('popstate', rewriteHistoryAfterBack);
  134. history.back();
  135. function rewriteHistoryAfterBack() {
  136. window.removeEventListener('popstate', rewriteHistoryAfterBack);
  137. window.addEventListener('popstate', rewriteHistoryAfterForward);
  138. self._pushToHistory(params, false, true);
  139. history.forward();
  140. }
  141. function rewriteHistoryAfterForward() {
  142. window.removeEventListener('popstate', rewriteHistoryAfterForward);
  143. self.allowHashChange = true;
  144. self.historyUnlocked = true;
  145. callback();
  146. }
  147. }
  148. function pdfHistoryBeforeUnload() {
  149. var previousParams = self._getPreviousParams(null, true);
  150. if (previousParams) {
  151. var replacePrevious = (!self.current.dest &&
  152. self.current.hash !== self.previousHash);
  153. self._pushToHistory(previousParams, false, replacePrevious);
  154. self._updatePreviousBookmark();
  155. }
  156. // Remove the event listener when navigating away from the document,
  157. // since 'beforeunload' prevents Firefox from caching the document.
  158. window.removeEventListener('beforeunload', pdfHistoryBeforeUnload,
  159. false);
  160. }
  161. window.addEventListener('beforeunload', pdfHistoryBeforeUnload, false);
  162. window.addEventListener('pageshow', function pdfHistoryPageShow(evt) {
  163. // If the entire viewer (including the PDF file) is cached in
  164. // the browser, we need to reattach the 'beforeunload' event listener
  165. // since the 'DOMContentLoaded' event is not fired on 'pageshow'.
  166. window.addEventListener('beforeunload', pdfHistoryBeforeUnload, false);
  167. }, false);
  168. window.addEventListener('presentationmodechanged', function(e) {
  169. self.isViewerInPresentationMode = !!e.detail.active;
  170. });
  171. },
  172. clearHistoryState: function pdfHistory_clearHistoryState() {
  173. this._pushOrReplaceState(null, true);
  174. },
  175. _isStateObjectDefined: function pdfHistory_isStateObjectDefined(state) {
  176. return (state && state.uid >= 0 &&
  177. state.fingerprint && this.fingerprint === state.fingerprint &&
  178. state.target && state.target.hash) ? true : false;
  179. },
  180. _pushOrReplaceState: function pdfHistory_pushOrReplaceState(stateObj,
  181. replace) {
  182. if (replace) {
  183. window.history.replaceState(stateObj, '', document.URL);
  184. } else {
  185. window.history.pushState(stateObj, '', document.URL);
  186. }
  187. },
  188. get isHashChangeUnlocked() {
  189. if (!this.initialized) {
  190. return true;
  191. }
  192. return this.allowHashChange;
  193. },
  194. _updatePreviousBookmark: function pdfHistory_updatePreviousBookmark() {
  195. if (this.updatePreviousBookmark &&
  196. this.currentBookmark && this.currentPage) {
  197. this.previousBookmark = this.currentBookmark;
  198. this.previousPage = this.currentPage;
  199. this.updatePreviousBookmark = false;
  200. }
  201. },
  202. updateCurrentBookmark: function pdfHistoryUpdateCurrentBookmark(bookmark,
  203. pageNum) {
  204. if (this.initialized) {
  205. this.currentBookmark = bookmark.substring(1);
  206. this.currentPage = pageNum | 0;
  207. this._updatePreviousBookmark();
  208. }
  209. },
  210. updateNextHashParam: function pdfHistoryUpdateNextHashParam(param) {
  211. if (this.initialized) {
  212. this.nextHashParam = param;
  213. }
  214. },
  215. push: function pdfHistoryPush(params, isInitialBookmark) {
  216. if (!(this.initialized && this.historyUnlocked)) {
  217. return;
  218. }
  219. if (params.dest && !params.hash) {
  220. params.hash = (this.current.hash && this.current.dest &&
  221. this.current.dest === params.dest) ?
  222. this.current.hash :
  223. this.linkService.getDestinationHash(params.dest).split('#')[1];
  224. }
  225. if (params.page) {
  226. params.page |= 0;
  227. }
  228. if (isInitialBookmark) {
  229. var target = window.history.state.target;
  230. if (!target) {
  231. // Invoked when the user specifies an initial bookmark,
  232. // thus setting initialBookmark, when the document is loaded.
  233. this._pushToHistory(params, false);
  234. this.previousHash = window.location.hash.substring(1);
  235. }
  236. this.updatePreviousBookmark = this.nextHashParam ? false : true;
  237. if (target) {
  238. // If the current document is reloaded,
  239. // avoid creating duplicate entries in the history.
  240. this._updatePreviousBookmark();
  241. }
  242. return;
  243. }
  244. if (this.nextHashParam) {
  245. if (this.nextHashParam === params.hash) {
  246. this.nextHashParam = null;
  247. this.updatePreviousBookmark = true;
  248. return;
  249. } else {
  250. this.nextHashParam = null;
  251. }
  252. }
  253. if (params.hash) {
  254. if (this.current.hash) {
  255. if (this.current.hash !== params.hash) {
  256. this._pushToHistory(params, true);
  257. } else {
  258. if (!this.current.page && params.page) {
  259. this._pushToHistory(params, false, true);
  260. }
  261. this.updatePreviousBookmark = true;
  262. }
  263. } else {
  264. this._pushToHistory(params, true);
  265. }
  266. } else if (this.current.page && params.page &&
  267. this.current.page !== params.page) {
  268. this._pushToHistory(params, true);
  269. }
  270. },
  271. _getPreviousParams: function pdfHistory_getPreviousParams(onlyCheckPage,
  272. beforeUnload) {
  273. if (!(this.currentBookmark && this.currentPage)) {
  274. return null;
  275. } else if (this.updatePreviousBookmark) {
  276. this.updatePreviousBookmark = false;
  277. }
  278. if (this.uid > 0 && !(this.previousBookmark && this.previousPage)) {
  279. // Prevent the history from getting stuck in the current state,
  280. // effectively preventing the user from going back/forward in
  281. // the history.
  282. //
  283. // This happens if the current position in the document didn't change
  284. // when the history was previously updated. The reasons for this are
  285. // either:
  286. // 1. The current zoom value is such that the document does not need to,
  287. // or cannot, be scrolled to display the destination.
  288. // 2. The previous destination is broken, and doesn't actally point to a
  289. // position within the document.
  290. // (This is either due to a bad PDF generator, or the user making a
  291. // mistake when entering a destination in the hash parameters.)
  292. return null;
  293. }
  294. if ((!this.current.dest && !onlyCheckPage) || beforeUnload) {
  295. if (this.previousBookmark === this.currentBookmark) {
  296. return null;
  297. }
  298. } else if (this.current.page || onlyCheckPage) {
  299. if (this.previousPage === this.currentPage) {
  300. return null;
  301. }
  302. } else {
  303. return null;
  304. }
  305. var params = {hash: this.currentBookmark, page: this.currentPage};
  306. if (this.isViewerInPresentationMode) {
  307. params.hash = null;
  308. }
  309. return params;
  310. },
  311. _stateObj: function pdfHistory_stateObj(params) {
  312. return {fingerprint: this.fingerprint, uid: this.uid, target: params};
  313. },
  314. _pushToHistory: function pdfHistory_pushToHistory(params,
  315. addPrevious, overwrite) {
  316. if (!this.initialized) {
  317. return;
  318. }
  319. if (!params.hash && params.page) {
  320. params.hash = ('page=' + params.page);
  321. }
  322. if (addPrevious && !overwrite) {
  323. var previousParams = this._getPreviousParams();
  324. if (previousParams) {
  325. var replacePrevious = (!this.current.dest &&
  326. this.current.hash !== this.previousHash);
  327. this._pushToHistory(previousParams, false, replacePrevious);
  328. }
  329. }
  330. this._pushOrReplaceState(this._stateObj(params),
  331. (overwrite || this.uid === 0));
  332. this.currentUid = this.uid++;
  333. this.current = params;
  334. this.updatePreviousBookmark = true;
  335. },
  336. _goTo: function pdfHistory_goTo(state) {
  337. if (!(this.initialized && this.historyUnlocked &&
  338. this._isStateObjectDefined(state))) {
  339. return;
  340. }
  341. if (!this.reInitialized && state.uid < this.currentUid) {
  342. var previousParams = this._getPreviousParams(true);
  343. if (previousParams) {
  344. this._pushToHistory(this.current, false);
  345. this._pushToHistory(previousParams, false);
  346. this.currentUid = state.uid;
  347. window.history.back();
  348. return;
  349. }
  350. }
  351. this.historyUnlocked = false;
  352. if (state.target.dest) {
  353. this.linkService.navigateTo(state.target.dest);
  354. } else {
  355. this.linkService.setHash(state.target.hash);
  356. }
  357. this.currentUid = state.uid;
  358. if (state.uid > this.uid) {
  359. this.uid = state.uid;
  360. }
  361. this.current = state.target;
  362. this.updatePreviousBookmark = true;
  363. var currentHash = window.location.hash.substring(1);
  364. if (this.previousHash !== currentHash) {
  365. this.allowHashChange = false;
  366. }
  367. this.previousHash = currentHash;
  368. this.historyUnlocked = true;
  369. },
  370. back: function pdfHistoryBack() {
  371. this.go(-1);
  372. },
  373. forward: function pdfHistoryForward() {
  374. this.go(1);
  375. },
  376. go: function pdfHistoryGo(direction) {
  377. if (this.initialized && this.historyUnlocked) {
  378. var state = window.history.state;
  379. if (direction === -1 && state && state.uid > 0) {
  380. window.history.back();
  381. } else if (direction === 1 && state && state.uid < (this.uid - 1)) {
  382. window.history.forward();
  383. }
  384. }
  385. }
  386. };
  387. exports.PDFHistory = PDFHistory;
  388. }));
  389. (function (root, factory) {
  390. {
  391. factory((root.pdfjsWebPDFRenderingQueue = {}));
  392. }
  393. }(this, function (exports) {
  394. var CLEANUP_TIMEOUT = 30000;
  395. var RenderingStates = {
  396. INITIAL: 0,
  397. RUNNING: 1,
  398. PAUSED: 2,
  399. FINISHED: 3
  400. };
  401. /**
  402. * Controls rendering of the views for pages and thumbnails.
  403. * @class
  404. */
  405. var PDFRenderingQueue = (function PDFRenderingQueueClosure() {
  406. /**
  407. * @constructs
  408. */
  409. function PDFRenderingQueue() {
  410. this.pdfViewer = null;
  411. this.pdfThumbnailViewer = null;
  412. this.onIdle = null;
  413. this.highestPriorityPage = null;
  414. this.idleTimeout = null;
  415. this.printing = false;
  416. this.isThumbnailViewEnabled = false;
  417. }
  418. PDFRenderingQueue.prototype = /** @lends PDFRenderingQueue.prototype */ {
  419. /**
  420. * @param {PDFViewer} pdfViewer
  421. */
  422. setViewer: function PDFRenderingQueue_setViewer(pdfViewer) {
  423. this.pdfViewer = pdfViewer;
  424. },
  425. /**
  426. * @param {PDFThumbnailViewer} pdfThumbnailViewer
  427. */
  428. setThumbnailViewer:
  429. function PDFRenderingQueue_setThumbnailViewer(pdfThumbnailViewer) {
  430. this.pdfThumbnailViewer = pdfThumbnailViewer;
  431. },
  432. /**
  433. * @param {IRenderableView} view
  434. * @returns {boolean}
  435. */
  436. isHighestPriority: function PDFRenderingQueue_isHighestPriority(view) {
  437. return this.highestPriorityPage === view.renderingId;
  438. },
  439. renderHighestPriority: function
  440. PDFRenderingQueue_renderHighestPriority(currentlyVisiblePages) {
  441. if (this.idleTimeout) {
  442. clearTimeout(this.idleTimeout);
  443. this.idleTimeout = null;
  444. }
  445. // Pages have a higher priority than thumbnails, so check them first.
  446. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  447. return;
  448. }
  449. // No pages needed rendering so check thumbnails.
  450. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  451. if (this.pdfThumbnailViewer.forceRendering()) {
  452. return;
  453. }
  454. }
  455. if (this.printing) {
  456. // If printing is currently ongoing do not reschedule cleanup.
  457. return;
  458. }
  459. if (this.onIdle) {
  460. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  461. }
  462. },
  463. getHighestPriority: function
  464. PDFRenderingQueue_getHighestPriority(visible, views, scrolledDown) {
  465. // The state has changed figure out which page has the highest priority to
  466. // render next (if any).
  467. // Priority:
  468. // 1 visible pages
  469. // 2 if last scrolled down page after the visible pages
  470. // 2 if last scrolled up page before the visible pages
  471. var visibleViews = visible.views;
  472. var numVisible = visibleViews.length;
  473. if (numVisible === 0) {
  474. return false;
  475. }
  476. for (var i = 0; i < numVisible; ++i) {
  477. var view = visibleViews[i].view;
  478. if (!this.isViewFinished(view)) {
  479. return view;
  480. }
  481. }
  482. // All the visible views have rendered, try to render next/previous pages.
  483. if (scrolledDown) {
  484. var nextPageIndex = visible.last.id;
  485. // ID's start at 1 so no need to add 1.
  486. if (views[nextPageIndex] &&
  487. !this.isViewFinished(views[nextPageIndex])) {
  488. return views[nextPageIndex];
  489. }
  490. } else {
  491. var previousPageIndex = visible.first.id - 2;
  492. if (views[previousPageIndex] &&
  493. !this.isViewFinished(views[previousPageIndex])) {
  494. return views[previousPageIndex];
  495. }
  496. }
  497. // Everything that needs to be rendered has been.
  498. return null;
  499. },
  500. /**
  501. * @param {IRenderableView} view
  502. * @returns {boolean}
  503. */
  504. isViewFinished: function PDFRenderingQueue_isViewFinished(view) {
  505. return view.renderingState === RenderingStates.FINISHED;
  506. },
  507. /**
  508. * Render a page or thumbnail view. This calls the appropriate function
  509. * based on the views state. If the view is already rendered it will return
  510. * false.
  511. * @param {IRenderableView} view
  512. */
  513. renderView: function PDFRenderingQueue_renderView(view) {
  514. var state = view.renderingState;
  515. switch (state) {
  516. case RenderingStates.FINISHED:
  517. return false;
  518. case RenderingStates.PAUSED:
  519. this.highestPriorityPage = view.renderingId;
  520. view.resume();
  521. break;
  522. case RenderingStates.RUNNING:
  523. this.highestPriorityPage = view.renderingId;
  524. break;
  525. case RenderingStates.INITIAL:
  526. this.highestPriorityPage = view.renderingId;
  527. var continueRendering = function () {
  528. this.renderHighestPriority();
  529. }.bind(this);
  530. view.draw().then(continueRendering, continueRendering);
  531. break;
  532. }
  533. return true;
  534. },
  535. };
  536. return PDFRenderingQueue;
  537. })();
  538. exports.RenderingStates = RenderingStates;
  539. exports.PDFRenderingQueue = PDFRenderingQueue;
  540. }));
  541. (function (root, factory) {
  542. {
  543. factory((root.pdfjsWebDownloadManager = {}), root.pdfjsWebPDFJS);
  544. }
  545. }(this, function (exports, pdfjsLib) {
  546. function download(blobUrl, filename) {
  547. var a = document.createElement('a');
  548. if (a.click) {
  549. // Use a.click() if available. Otherwise, Chrome might show
  550. // "Unsafe JavaScript attempt to initiate a navigation change
  551. // for frame with URL" and not open the PDF at all.
  552. // Supported by (not mentioned = untested):
  553. // - Firefox 6 - 19 (4- does not support a.click, 5 ignores a.click)
  554. // - Chrome 19 - 26 (18- does not support a.click)
  555. // - Opera 9 - 12.15
  556. // - Internet Explorer 6 - 10
  557. // - Safari 6 (5.1- does not support a.click)
  558. a.href = blobUrl;
  559. a.target = '_parent';
  560. // Use a.download if available. This increases the likelihood that
  561. // the file is downloaded instead of opened by another PDF plugin.
  562. if ('download' in a) {
  563. a.download = filename;
  564. }
  565. // <a> must be in the document for IE and recent Firefox versions.
  566. // (otherwise .click() is ignored)
  567. (document.body || document.documentElement).appendChild(a);
  568. a.click();
  569. a.parentNode.removeChild(a);
  570. } else {
  571. if (window.top === window &&
  572. blobUrl.split('#')[0] === window.location.href.split('#')[0]) {
  573. // If _parent == self, then opening an identical URL with different
  574. // location hash will only cause a navigation, not a download.
  575. var padCharacter = blobUrl.indexOf('?') === -1 ? '?' : '&';
  576. blobUrl = blobUrl.replace(/#|$/, padCharacter + '$&');
  577. }
  578. window.open(blobUrl, '_parent');
  579. }
  580. }
  581. function DownloadManager() {}
  582. DownloadManager.prototype = {
  583. downloadUrl: function DownloadManager_downloadUrl(url, filename) {
  584. if (!pdfjsLib.isValidUrl(url, true)) {
  585. return; // restricted/invalid URL
  586. }
  587. download(url + '#pdfjs.action=download', filename);
  588. },
  589. downloadData: function DownloadManager_downloadData(data, filename,
  590. contentType) {
  591. if (navigator.msSaveBlob) { // IE10 and above
  592. return navigator.msSaveBlob(new Blob([data], { type: contentType }),
  593. filename);
  594. }
  595. var blobUrl = pdfjsLib.createObjectURL(data, contentType,
  596. pdfjsLib.PDFJS.disableCreateObjectURL);
  597. download(blobUrl, filename);
  598. },
  599. download: function DownloadManager_download(blob, url, filename) {
  600. if (!URL) {
  601. // URL.createObjectURL is not supported
  602. this.downloadUrl(url, filename);
  603. return;
  604. }
  605. if (navigator.msSaveBlob) {
  606. // IE10 / IE11
  607. if (!navigator.msSaveBlob(blob, filename)) {
  608. this.downloadUrl(url, filename);
  609. }
  610. return;
  611. }
  612. var blobUrl = URL.createObjectURL(blob);
  613. download(blobUrl, filename);
  614. }
  615. };
  616. exports.DownloadManager = DownloadManager;
  617. }));
  618. (function (root, factory) {
  619. {
  620. factory((root.pdfjsWebTextLayerBuilder = {}), root.pdfjsWebPDFJS);
  621. }
  622. }(this, function (exports, pdfjsLib) {
  623. /**
  624. * @typedef {Object} TextLayerBuilderOptions
  625. * @property {HTMLDivElement} textLayerDiv - The text layer container.
  626. * @property {number} pageIndex - The page index.
  627. * @property {PageViewport} viewport - The viewport of the text layer.
  628. * @property {PDFFindController} findController
  629. */
  630. /**
  631. * TextLayerBuilder provides text-selection functionality for the PDF.
  632. * It does this by creating overlay divs over the PDF text. These divs
  633. * contain text that matches the PDF text they are overlaying. This object
  634. * also provides a way to highlight text that is being searched for.
  635. * @class
  636. */
  637. var TextLayerBuilder = (function TextLayerBuilderClosure() {
  638. function TextLayerBuilder(options) {
  639. this.textLayerDiv = options.textLayerDiv;
  640. this.renderingDone = false;
  641. this.divContentDone = false;
  642. this.pageIdx = options.pageIndex;
  643. this.pageNumber = this.pageIdx + 1;
  644. this.matches = [];
  645. this.viewport = options.viewport;
  646. this.textDivs = [];
  647. this.findController = options.findController || null;
  648. this.textLayerRenderTask = null;
  649. this._bindMouse();
  650. }
  651. TextLayerBuilder.prototype = {
  652. _finishRendering: function TextLayerBuilder_finishRendering() {
  653. this.renderingDone = true;
  654. var endOfContent = document.createElement('div');
  655. endOfContent.className = 'endOfContent';
  656. this.textLayerDiv.appendChild(endOfContent);
  657. var event = document.createEvent('CustomEvent');
  658. event.initCustomEvent('textlayerrendered', true, true, {
  659. pageNumber: this.pageNumber
  660. });
  661. this.textLayerDiv.dispatchEvent(event);
  662. },
  663. /**
  664. * Renders the text layer.
  665. * @param {number} timeout (optional) if specified, the rendering waits
  666. * for specified amount of ms.
  667. */
  668. render: function TextLayerBuilder_render(timeout) {
  669. if (!this.divContentDone || this.renderingDone) {
  670. return;
  671. }
  672. if (this.textLayerRenderTask) {
  673. this.textLayerRenderTask.cancel();
  674. this.textLayerRenderTask = null;
  675. }
  676. this.textDivs = [];
  677. var textLayerFrag = document.createDocumentFragment();
  678. this.textLayerRenderTask = pdfjsLib.renderTextLayer({
  679. textContent: this.textContent,
  680. container: textLayerFrag,
  681. viewport: this.viewport,
  682. textDivs: this.textDivs,
  683. timeout: timeout
  684. });
  685. this.textLayerRenderTask.promise.then(function () {
  686. this.textLayerDiv.appendChild(textLayerFrag);
  687. this._finishRendering();
  688. this.updateMatches();
  689. }.bind(this), function (reason) {
  690. // canceled or failed to render text layer -- skipping errors
  691. });
  692. },
  693. setTextContent: function TextLayerBuilder_setTextContent(textContent) {
  694. if (this.textLayerRenderTask) {
  695. this.textLayerRenderTask.cancel();
  696. this.textLayerRenderTask = null;
  697. }
  698. this.textContent = textContent;
  699. this.divContentDone = true;
  700. },
  701. convertMatches: function TextLayerBuilder_convertMatches(matches) {
  702. var i = 0;
  703. var iIndex = 0;
  704. var bidiTexts = this.textContent.items;
  705. var end = bidiTexts.length - 1;
  706. var queryLen = (this.findController === null ?
  707. 0 : this.findController.state.query.length);
  708. var ret = [];
  709. for (var m = 0, len = matches.length; m < len; m++) {
  710. // Calculate the start position.
  711. var matchIdx = matches[m];
  712. // Loop over the divIdxs.
  713. while (i !== end && matchIdx >= (iIndex + bidiTexts[i].str.length)) {
  714. iIndex += bidiTexts[i].str.length;
  715. i++;
  716. }
  717. if (i === bidiTexts.length) {
  718. console.error('Could not find a matching mapping');
  719. }
  720. var match = {
  721. begin: {
  722. divIdx: i,
  723. offset: matchIdx - iIndex
  724. }
  725. };
  726. // Calculate the end position.
  727. matchIdx += queryLen;
  728. // Somewhat the same array as above, but use > instead of >= to get
  729. // the end position right.
  730. while (i !== end && matchIdx > (iIndex + bidiTexts[i].str.length)) {
  731. iIndex += bidiTexts[i].str.length;
  732. i++;
  733. }
  734. match.end = {
  735. divIdx: i,
  736. offset: matchIdx - iIndex
  737. };
  738. ret.push(match);
  739. }
  740. return ret;
  741. },
  742. renderMatches: function TextLayerBuilder_renderMatches(matches) {
  743. // Early exit if there is nothing to render.
  744. if (matches.length === 0) {
  745. return;
  746. }
  747. var bidiTexts = this.textContent.items;
  748. var textDivs = this.textDivs;
  749. var prevEnd = null;
  750. var pageIdx = this.pageIdx;
  751. var isSelectedPage = (this.findController === null ?
  752. false : (pageIdx === this.findController.selected.pageIdx));
  753. var selectedMatchIdx = (this.findController === null ?
  754. -1 : this.findController.selected.matchIdx);
  755. var highlightAll = (this.findController === null ?
  756. false : this.findController.state.highlightAll);
  757. var infinity = {
  758. divIdx: -1,
  759. offset: undefined
  760. };
  761. function beginText(begin, className) {
  762. var divIdx = begin.divIdx;
  763. textDivs[divIdx].textContent = '';
  764. appendTextToDiv(divIdx, 0, begin.offset, className);
  765. }
  766. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  767. var div = textDivs[divIdx];
  768. var content = bidiTexts[divIdx].str.substring(fromOffset, toOffset);
  769. var node = document.createTextNode(content);
  770. if (className) {
  771. var span = document.createElement('span');
  772. span.className = className;
  773. span.appendChild(node);
  774. div.appendChild(span);
  775. return;
  776. }
  777. div.appendChild(node);
  778. }
  779. var i0 = selectedMatchIdx, i1 = i0 + 1;
  780. if (highlightAll) {
  781. i0 = 0;
  782. i1 = matches.length;
  783. } else if (!isSelectedPage) {
  784. // Not highlighting all and this isn't the selected page, so do nothing.
  785. return;
  786. }
  787. for (var i = i0; i < i1; i++) {
  788. var match = matches[i];
  789. var begin = match.begin;
  790. var end = match.end;
  791. var isSelected = (isSelectedPage && i === selectedMatchIdx);
  792. var highlightSuffix = (isSelected ? ' selected' : '');
  793. if (this.findController) {
  794. this.findController.updateMatchPosition(pageIdx, i, textDivs,
  795. begin.divIdx, end.divIdx);
  796. }
  797. // Match inside new div.
  798. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  799. // If there was a previous div, then add the text at the end.
  800. if (prevEnd !== null) {
  801. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  802. }
  803. // Clear the divs and set the content until the starting point.
  804. beginText(begin);
  805. } else {
  806. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  807. }
  808. if (begin.divIdx === end.divIdx) {
  809. appendTextToDiv(begin.divIdx, begin.offset, end.offset,
  810. 'highlight' + highlightSuffix);
  811. } else {
  812. appendTextToDiv(begin.divIdx, begin.offset, infinity.offset,
  813. 'highlight begin' + highlightSuffix);
  814. for (var n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  815. textDivs[n0].className = 'highlight middle' + highlightSuffix;
  816. }
  817. beginText(end, 'highlight end' + highlightSuffix);
  818. }
  819. prevEnd = end;
  820. }
  821. if (prevEnd) {
  822. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  823. }
  824. },
  825. updateMatches: function TextLayerBuilder_updateMatches() {
  826. // Only show matches when all rendering is done.
  827. if (!this.renderingDone) {
  828. return;
  829. }
  830. // Clear all matches.
  831. var matches = this.matches;
  832. var textDivs = this.textDivs;
  833. var bidiTexts = this.textContent.items;
  834. var clearedUntilDivIdx = -1;
  835. // Clear all current matches.
  836. for (var i = 0, len = matches.length; i < len; i++) {
  837. var match = matches[i];
  838. var begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  839. for (var n = begin, end = match.end.divIdx; n <= end; n++) {
  840. var div = textDivs[n];
  841. div.textContent = bidiTexts[n].str;
  842. div.className = '';
  843. }
  844. clearedUntilDivIdx = match.end.divIdx + 1;
  845. }
  846. if (this.findController === null || !this.findController.active) {
  847. return;
  848. }
  849. // Convert the matches on the page controller into the match format
  850. // used for the textLayer.
  851. this.matches = this.convertMatches(this.findController === null ?
  852. [] : (this.findController.pageMatches[this.pageIdx] || []));
  853. this.renderMatches(this.matches);
  854. },
  855. /**
  856. * Fixes text selection: adds additional div where mouse was clicked.
  857. * This reduces flickering of the content if mouse slowly dragged down/up.
  858. * @private
  859. */
  860. _bindMouse: function TextLayerBuilder_bindMouse() {
  861. var div = this.textLayerDiv;
  862. div.addEventListener('mousedown', function (e) {
  863. var end = div.querySelector('.endOfContent');
  864. if (!end) {
  865. return;
  866. }
  867. // On non-Firefox browsers, the selection will feel better if the height
  868. // of the endOfContent div will be adjusted to start at mouse click
  869. // location -- this will avoid flickering when selections moves up.
  870. // However it does not work when selection started on empty space.
  871. var adjustTop = e.target !== div;
  872. adjustTop = adjustTop && window.getComputedStyle(end).
  873. getPropertyValue('-moz-user-select') !== 'none';
  874. if (adjustTop) {
  875. var divBounds = div.getBoundingClientRect();
  876. var r = Math.max(0, (e.pageY - divBounds.top) / divBounds.height);
  877. end.style.top = (r * 100).toFixed(2) + '%';
  878. }
  879. end.classList.add('active');
  880. });
  881. div.addEventListener('mouseup', function (e) {
  882. var end = div.querySelector('.endOfContent');
  883. if (!end) {
  884. return;
  885. }
  886. end.style.top = '';
  887. end.classList.remove('active');
  888. });
  889. },
  890. };
  891. return TextLayerBuilder;
  892. })();
  893. /**
  894. * @constructor
  895. * @implements IPDFTextLayerFactory
  896. */
  897. function DefaultTextLayerFactory() {}
  898. DefaultTextLayerFactory.prototype = {
  899. /**
  900. * @param {HTMLDivElement} textLayerDiv
  901. * @param {number} pageIndex
  902. * @param {PageViewport} viewport
  903. * @returns {TextLayerBuilder}
  904. */
  905. createTextLayerBuilder: function (textLayerDiv, pageIndex, viewport) {
  906. return new TextLayerBuilder({
  907. textLayerDiv: textLayerDiv,
  908. pageIndex: pageIndex,
  909. viewport: viewport
  910. });
  911. }
  912. };
  913. exports.TextLayerBuilder = TextLayerBuilder;
  914. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  915. }));
  916. (function (root, factory) {
  917. {
  918. factory((root.pdfjsWebUIUtils = {}), root.pdfjsWebPDFJS);
  919. }
  920. }(this, function (exports, pdfjsLib) {
  921. var CSS_UNITS = 96.0 / 72.0;
  922. var DEFAULT_SCALE_VALUE = 'auto';
  923. var DEFAULT_SCALE = 1.0;
  924. var UNKNOWN_SCALE = 0;
  925. var MAX_AUTO_SCALE = 1.25;
  926. var SCROLLBAR_PADDING = 40;
  927. var VERTICAL_PADDING = 5;
  928. var mozL10n = document.mozL10n || document.webL10n;
  929. var PDFJS = pdfjsLib.PDFJS;
  930. /**
  931. * Disables fullscreen support, and by extension Presentation Mode,
  932. * in browsers which support the fullscreen API.
  933. * @var {boolean}
  934. */
  935. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  936. false : PDFJS.disableFullscreen);
  937. /**
  938. * Enables CSS only zooming.
  939. * @var {boolean}
  940. */
  941. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  942. false : PDFJS.useOnlyCssZoom);
  943. /**
  944. * The maximum supported canvas size in total pixels e.g. width * height.
  945. * The default value is 4096 * 4096. Use -1 for no limit.
  946. * @var {number}
  947. */
  948. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  949. 16777216 : PDFJS.maxCanvasPixels);
  950. /**
  951. * Disables saving of the last position of the viewed PDF.
  952. * @var {boolean}
  953. */
  954. PDFJS.disableHistory = (PDFJS.disableHistory === undefined ?
  955. false : PDFJS.disableHistory);
  956. /**
  957. * Disables creation of the text layer that used for text selection and search.
  958. * @var {boolean}
  959. */
  960. PDFJS.disableTextLayer = (PDFJS.disableTextLayer === undefined ?
  961. false : PDFJS.disableTextLayer);
  962. /**
  963. * Disables maintaining the current position in the document when zooming.
  964. */
  965. PDFJS.ignoreCurrentPositionOnZoom = (PDFJS.ignoreCurrentPositionOnZoom ===
  966. undefined ? false : PDFJS.ignoreCurrentPositionOnZoom);
  967. /**
  968. * Interface locale settings.
  969. * @var {string}
  970. */
  971. PDFJS.locale = (PDFJS.locale === undefined ? navigator.language : PDFJS.locale);
  972. /**
  973. * Returns scale factor for the canvas. It makes sense for the HiDPI displays.
  974. * @return {Object} The object with horizontal (sx) and vertical (sy)
  975. scales. The scaled property is set to false if scaling is
  976. not required, true otherwise.
  977. */
  978. function getOutputScale(ctx) {
  979. var devicePixelRatio = window.devicePixelRatio || 1;
  980. var backingStoreRatio = ctx.webkitBackingStorePixelRatio ||
  981. ctx.mozBackingStorePixelRatio ||
  982. ctx.msBackingStorePixelRatio ||
  983. ctx.oBackingStorePixelRatio ||
  984. ctx.backingStorePixelRatio || 1;
  985. var pixelRatio = devicePixelRatio / backingStoreRatio;
  986. return {
  987. sx: pixelRatio,
  988. sy: pixelRatio,
  989. scaled: pixelRatio !== 1
  990. };
  991. }
  992. /**
  993. * Scrolls specified element into view of its parent.
  994. * @param {Object} element - The element to be visible.
  995. * @param {Object} spot - An object with optional top and left properties,
  996. * specifying the offset from the top left edge.
  997. * @param {boolean} skipOverflowHiddenElements - Ignore elements that have
  998. * the CSS rule `overflow: hidden;` set. The default is false.
  999. */
  1000. function scrollIntoView(element, spot, skipOverflowHiddenElements) {
  1001. // Assuming offsetParent is available (it's not available when viewer is in
  1002. // hidden iframe or object). We have to scroll: if the offsetParent is not set
  1003. // producing the error. See also animationStartedClosure.
  1004. var parent = element.offsetParent;
  1005. if (!parent) {
  1006. console.error('offsetParent is not set -- cannot scroll');
  1007. return;
  1008. }
  1009. var checkOverflow = skipOverflowHiddenElements || false;
  1010. var offsetY = element.offsetTop + element.clientTop;
  1011. var offsetX = element.offsetLeft + element.clientLeft;
  1012. while (parent.clientHeight === parent.scrollHeight ||
  1013. (checkOverflow && getComputedStyle(parent).overflow === 'hidden')) {
  1014. if (parent.dataset._scaleY) {
  1015. offsetY /= parent.dataset._scaleY;
  1016. offsetX /= parent.dataset._scaleX;
  1017. }
  1018. offsetY += parent.offsetTop;
  1019. offsetX += parent.offsetLeft;
  1020. parent = parent.offsetParent;
  1021. if (!parent) {
  1022. return; // no need to scroll
  1023. }
  1024. }
  1025. if (spot) {
  1026. if (spot.top !== undefined) {
  1027. offsetY += spot.top;
  1028. }
  1029. if (spot.left !== undefined) {
  1030. offsetX += spot.left;
  1031. parent.scrollLeft = offsetX;
  1032. }
  1033. }
  1034. parent.scrollTop = offsetY;
  1035. }
  1036. /**
  1037. * Helper function to start monitoring the scroll event and converting them into
  1038. * PDF.js friendly one: with scroll debounce and scroll direction.
  1039. */
  1040. function watchScroll(viewAreaElement, callback) {
  1041. var debounceScroll = function debounceScroll(evt) {
  1042. if (rAF) {
  1043. return;
  1044. }
  1045. // schedule an invocation of scroll for next animation frame.
  1046. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  1047. rAF = null;
  1048. var currentY = viewAreaElement.scrollTop;
  1049. var lastY = state.lastY;
  1050. if (currentY !== lastY) {
  1051. state.down = currentY > lastY;
  1052. }
  1053. state.lastY = currentY;
  1054. callback(state);
  1055. });
  1056. };
  1057. var state = {
  1058. down: true,
  1059. lastY: viewAreaElement.scrollTop,
  1060. _eventHandler: debounceScroll
  1061. };
  1062. var rAF = null;
  1063. viewAreaElement.addEventListener('scroll', debounceScroll, true);
  1064. return state;
  1065. }
  1066. /**
  1067. * Helper function to parse query string (e.g. ?param1=value&parm2=...).
  1068. */
  1069. function parseQueryString(query) {
  1070. var parts = query.split('&');
  1071. var params = {};
  1072. for (var i = 0, ii = parts.length; i < ii; ++i) {
  1073. var param = parts[i].split('=');
  1074. var key = param[0].toLowerCase();
  1075. var value = param.length > 1 ? param[1] : null;
  1076. params[decodeURIComponent(key)] = decodeURIComponent(value);
  1077. }
  1078. return params;
  1079. }
  1080. /**
  1081. * Use binary search to find the index of the first item in a given array which
  1082. * passes a given condition. The items are expected to be sorted in the sense
  1083. * that if the condition is true for one item in the array, then it is also true
  1084. * for all following items.
  1085. *
  1086. * @returns {Number} Index of the first array element to pass the test,
  1087. * or |items.length| if no such element exists.
  1088. */
  1089. function binarySearchFirstItem(items, condition) {
  1090. var minIndex = 0;
  1091. var maxIndex = items.length - 1;
  1092. if (items.length === 0 || !condition(items[maxIndex])) {
  1093. return items.length;
  1094. }
  1095. if (condition(items[minIndex])) {
  1096. return minIndex;
  1097. }
  1098. while (minIndex < maxIndex) {
  1099. var currentIndex = (minIndex + maxIndex) >> 1;
  1100. var currentItem = items[currentIndex];
  1101. if (condition(currentItem)) {
  1102. maxIndex = currentIndex;
  1103. } else {
  1104. minIndex = currentIndex + 1;
  1105. }
  1106. }
  1107. return minIndex; /* === maxIndex */
  1108. }
  1109. /**
  1110. * Approximates float number as a fraction using Farey sequence (max order
  1111. * of 8).
  1112. * @param {number} x - Positive float number.
  1113. * @returns {Array} Estimated fraction: the first array item is a numerator,
  1114. * the second one is a denominator.
  1115. */
  1116. function approximateFraction(x) {
  1117. // Fast paths for int numbers or their inversions.
  1118. if (Math.floor(x) === x) {
  1119. return [x, 1];
  1120. }
  1121. var xinv = 1 / x;
  1122. var limit = 8;
  1123. if (xinv > limit) {
  1124. return [1, limit];
  1125. } else if (Math.floor(xinv) === xinv) {
  1126. return [1, xinv];
  1127. }
  1128. var x_ = x > 1 ? xinv : x;
  1129. // a/b and c/d are neighbours in Farey sequence.
  1130. var a = 0, b = 1, c = 1, d = 1;
  1131. // Limiting search to order 8.
  1132. while (true) {
  1133. // Generating next term in sequence (order of q).
  1134. var p = a + c, q = b + d;
  1135. if (q > limit) {
  1136. break;
  1137. }
  1138. if (x_ <= p / q) {
  1139. c = p; d = q;
  1140. } else {
  1141. a = p; b = q;
  1142. }
  1143. }
  1144. // Select closest of the neighbours to x.
  1145. if (x_ - a / b < c / d - x_) {
  1146. return x_ === x ? [a, b] : [b, a];
  1147. } else {
  1148. return x_ === x ? [c, d] : [d, c];
  1149. }
  1150. }
  1151. function roundToDivide(x, div) {
  1152. var r = x % div;
  1153. return r === 0 ? x : Math.round(x - r + div);
  1154. }
  1155. /**
  1156. * Generic helper to find out what elements are visible within a scroll pane.
  1157. */
  1158. function getVisibleElements(scrollEl, views, sortByVisibility) {
  1159. var top = scrollEl.scrollTop, bottom = top + scrollEl.clientHeight;
  1160. var left = scrollEl.scrollLeft, right = left + scrollEl.clientWidth;
  1161. function isElementBottomBelowViewTop(view) {
  1162. var element = view.div;
  1163. var elementBottom =
  1164. element.offsetTop + element.clientTop + element.clientHeight;
  1165. return elementBottom > top;
  1166. }
  1167. var visible = [], view, element;
  1168. var currentHeight, viewHeight, hiddenHeight, percentHeight;
  1169. var currentWidth, viewWidth;
  1170. var firstVisibleElementInd = (views.length === 0) ? 0 :
  1171. binarySearchFirstItem(views, isElementBottomBelowViewTop);
  1172. for (var i = firstVisibleElementInd, ii = views.length; i < ii; i++) {
  1173. view = views[i];
  1174. element = view.div;
  1175. currentHeight = element.offsetTop + element.clientTop;
  1176. viewHeight = element.clientHeight;
  1177. if (currentHeight > bottom) {
  1178. break;
  1179. }
  1180. currentWidth = element.offsetLeft + element.clientLeft;
  1181. viewWidth = element.clientWidth;
  1182. if (currentWidth + viewWidth < left || currentWidth > right) {
  1183. continue;
  1184. }
  1185. hiddenHeight = Math.max(0, top - currentHeight) +
  1186. Math.max(0, currentHeight + viewHeight - bottom);
  1187. percentHeight = ((viewHeight - hiddenHeight) * 100 / viewHeight) | 0;
  1188. visible.push({
  1189. id: view.id,
  1190. x: currentWidth,
  1191. y: currentHeight,
  1192. view: view,
  1193. percent: percentHeight
  1194. });
  1195. }
  1196. var first = visible[0];
  1197. var last = visible[visible.length - 1];
  1198. if (sortByVisibility) {
  1199. visible.sort(function(a, b) {
  1200. var pc = a.percent - b.percent;
  1201. if (Math.abs(pc) > 0.001) {
  1202. return -pc;
  1203. }
  1204. return a.id - b.id; // ensure stability
  1205. });
  1206. }
  1207. return {first: first, last: last, views: visible};
  1208. }
  1209. /**
  1210. * Event handler to suppress context menu.
  1211. */
  1212. function noContextMenuHandler(e) {
  1213. e.preventDefault();
  1214. }
  1215. /**
  1216. * Returns the filename or guessed filename from the url (see issue 3455).
  1217. * url {String} The original PDF location.
  1218. * @return {String} Guessed PDF file name.
  1219. */
  1220. function getPDFFileNameFromURL(url) {
  1221. var reURI = /^(?:([^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  1222. // SCHEME HOST 1.PATH 2.QUERY 3.REF
  1223. // Pattern to get last matching NAME.pdf
  1224. var reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  1225. var splitURI = reURI.exec(url);
  1226. var suggestedFilename = reFilename.exec(splitURI[1]) ||
  1227. reFilename.exec(splitURI[2]) ||
  1228. reFilename.exec(splitURI[3]);
  1229. if (suggestedFilename) {
  1230. suggestedFilename = suggestedFilename[0];
  1231. if (suggestedFilename.indexOf('%') !== -1) {
  1232. // URL-encoded %2Fpath%2Fto%2Ffile.pdf should be file.pdf
  1233. try {
  1234. suggestedFilename =
  1235. reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  1236. } catch(e) { // Possible (extremely rare) errors:
  1237. // URIError "Malformed URI", e.g. for "%AA.pdf"
  1238. // TypeError "null has no properties", e.g. for "%2F.pdf"
  1239. }
  1240. }
  1241. }
  1242. return suggestedFilename || 'document.pdf';
  1243. }
  1244. var ProgressBar = (function ProgressBarClosure() {
  1245. function clamp(v, min, max) {
  1246. return Math.min(Math.max(v, min), max);
  1247. }
  1248. function ProgressBar(id, opts) {
  1249. this.visible = true;
  1250. // Fetch the sub-elements for later.
  1251. this.div = document.querySelector(id + ' .progress');
  1252. // Get the loading bar element, so it can be resized to fit the viewer.
  1253. this.bar = this.div.parentNode;
  1254. // Get options, with sensible defaults.
  1255. this.height = opts.height || 100;
  1256. this.width = opts.width || 100;
  1257. this.units = opts.units || '%';
  1258. // Initialize heights.
  1259. this.div.style.height = this.height + this.units;
  1260. this.percent = 0;
  1261. }
  1262. ProgressBar.prototype = {
  1263. updateBar: function ProgressBar_updateBar() {
  1264. if (this._indeterminate) {
  1265. this.div.classList.add('indeterminate');
  1266. this.div.style.width = this.width + this.units;
  1267. return;
  1268. }
  1269. this.div.classList.remove('indeterminate');
  1270. var progressSize = this.width * this._percent / 100;
  1271. this.div.style.width = progressSize + this.units;
  1272. },
  1273. get percent() {
  1274. return this._percent;
  1275. },
  1276. set percent(val) {
  1277. this._indeterminate = isNaN(val);
  1278. this._percent = clamp(val, 0, 100);
  1279. this.updateBar();
  1280. },
  1281. setWidth: function ProgressBar_setWidth(viewer) {
  1282. if (viewer) {
  1283. var container = viewer.parentNode;
  1284. var scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  1285. if (scrollbarWidth > 0) {
  1286. this.bar.setAttribute('style', 'width: calc(100% - ' +
  1287. scrollbarWidth + 'px);');
  1288. }
  1289. }
  1290. },
  1291. hide: function ProgressBar_hide() {
  1292. if (!this.visible) {
  1293. return;
  1294. }
  1295. this.visible = false;
  1296. this.bar.classList.add('hidden');
  1297. document.body.classList.remove('loadingInProgress');
  1298. },
  1299. show: function ProgressBar_show() {
  1300. if (this.visible) {
  1301. return;
  1302. }
  1303. this.visible = true;
  1304. document.body.classList.add('loadingInProgress');
  1305. this.bar.classList.remove('hidden');
  1306. }
  1307. };
  1308. return ProgressBar;
  1309. })();
  1310. exports.CSS_UNITS = CSS_UNITS;
  1311. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  1312. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  1313. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  1314. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  1315. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  1316. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  1317. exports.mozL10n = mozL10n;
  1318. exports.ProgressBar = ProgressBar;
  1319. exports.getPDFFileNameFromURL = getPDFFileNameFromURL;
  1320. exports.noContextMenuHandler = noContextMenuHandler;
  1321. exports.parseQueryString = parseQueryString;
  1322. exports.getVisibleElements = getVisibleElements;
  1323. exports.roundToDivide = roundToDivide;
  1324. exports.approximateFraction = approximateFraction;
  1325. exports.getOutputScale = getOutputScale;
  1326. exports.scrollIntoView = scrollIntoView;
  1327. exports.watchScroll = watchScroll;
  1328. exports.binarySearchFirstItem = binarySearchFirstItem;
  1329. }));
  1330. (function (root, factory) {
  1331. {
  1332. factory((root.pdfjsWebPDFFindController = {}), root.pdfjsWebUIUtils);
  1333. }
  1334. }(this, function (exports, uiUtils, firefoxCom) {
  1335. var scrollIntoView = uiUtils.scrollIntoView;
  1336. var FindStates = {
  1337. FIND_FOUND: 0,
  1338. FIND_NOTFOUND: 1,
  1339. FIND_WRAPPED: 2,
  1340. FIND_PENDING: 3
  1341. };
  1342. var FIND_SCROLL_OFFSET_TOP = -50;
  1343. var FIND_SCROLL_OFFSET_LEFT = -400;
  1344. var CHARACTERS_TO_NORMALIZE = {
  1345. '\u2018': '\'', // Left single quotation mark
  1346. '\u2019': '\'', // Right single quotation mark
  1347. '\u201A': '\'', // Single low-9 quotation mark
  1348. '\u201B': '\'', // Single high-reversed-9 quotation mark
  1349. '\u201C': '"', // Left double quotation mark
  1350. '\u201D': '"', // Right double quotation mark
  1351. '\u201E': '"', // Double low-9 quotation mark
  1352. '\u201F': '"', // Double high-reversed-9 quotation mark
  1353. '\u00BC': '1/4', // Vulgar fraction one quarter
  1354. '\u00BD': '1/2', // Vulgar fraction one half
  1355. '\u00BE': '3/4', // Vulgar fraction three quarters
  1356. };
  1357. /**
  1358. * Provides "search" or "find" functionality for the PDF.
  1359. * This object actually performs the search for a given string.
  1360. */
  1361. var PDFFindController = (function PDFFindControllerClosure() {
  1362. function PDFFindController(options) {
  1363. this.pdfViewer = options.pdfViewer || null;
  1364. this.onUpdateResultsCount = null;
  1365. this.onUpdateState = null;
  1366. this.reset();
  1367. // Compile the regular expression for text normalization once.
  1368. var replace = Object.keys(CHARACTERS_TO_NORMALIZE).join('');
  1369. this.normalizationRegex = new RegExp('[' + replace + ']', 'g');
  1370. }
  1371. PDFFindController.prototype = {
  1372. listenWindowEvents: function PDFFindController_listenWindowEvents() {
  1373. var events = [
  1374. 'find',
  1375. 'findagain',
  1376. 'findhighlightallchange',
  1377. 'findcasesensitivitychange'
  1378. ];
  1379. var handleEvent = function (e) {
  1380. this.executeCommand(e.type, e.detail);
  1381. }.bind(this);
  1382. for (var i = 0, len = events.length; i < len; i++) {
  1383. window.addEventListener(events[i], handleEvent);
  1384. }
  1385. },
  1386. reset: function PDFFindController_reset() {
  1387. this.startedTextExtraction = false;
  1388. this.extractTextPromises = [];
  1389. this.pendingFindMatches = Object.create(null);
  1390. this.active = false; // If active, find results will be highlighted.
  1391. this.pageContents = []; // Stores the text for each page.
  1392. this.pageMatches = [];
  1393. this.matchCount = 0;
  1394. this.selected = { // Currently selected match.
  1395. pageIdx: -1,
  1396. matchIdx: -1
  1397. };
  1398. this.offset = { // Where the find algorithm currently is in the document.
  1399. pageIdx: null,
  1400. matchIdx: null
  1401. };
  1402. this.pagesToSearch = null;
  1403. this.resumePageIdx = null;
  1404. this.state = null;
  1405. this.dirtyMatch = false;
  1406. this.findTimeout = null;
  1407. this.firstPagePromise = new Promise(function (resolve) {
  1408. this.resolveFirstPage = resolve;
  1409. }.bind(this));
  1410. },
  1411. normalize: function PDFFindController_normalize(text) {
  1412. return text.replace(this.normalizationRegex, function (ch) {
  1413. return CHARACTERS_TO_NORMALIZE[ch];
  1414. });
  1415. },
  1416. calcFindMatch: function PDFFindController_calcFindMatch(pageIndex) {
  1417. var pageContent = this.normalize(this.pageContents[pageIndex]);
  1418. var query = this.normalize(this.state.query);
  1419. var caseSensitive = this.state.caseSensitive;
  1420. var queryLen = query.length;
  1421. if (queryLen === 0) {
  1422. // Do nothing: the matches should be wiped out already.
  1423. return;
  1424. }
  1425. if (!caseSensitive) {
  1426. pageContent = pageContent.toLowerCase();
  1427. query = query.toLowerCase();
  1428. }
  1429. var matches = [];
  1430. var matchIdx = -queryLen;
  1431. while (true) {
  1432. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  1433. if (matchIdx === -1) {
  1434. break;
  1435. }
  1436. matches.push(matchIdx);
  1437. }
  1438. this.pageMatches[pageIndex] = matches;
  1439. this.updatePage(pageIndex);
  1440. if (this.resumePageIdx === pageIndex) {
  1441. this.resumePageIdx = null;
  1442. this.nextPageMatch();
  1443. }
  1444. // Update the matches count
  1445. if (matches.length > 0) {
  1446. this.matchCount += matches.length;
  1447. this.updateUIResultsCount();
  1448. }
  1449. },
  1450. extractText: function PDFFindController_extractText() {
  1451. if (this.startedTextExtraction) {
  1452. return;
  1453. }
  1454. this.startedTextExtraction = true;
  1455. this.pageContents = [];
  1456. var extractTextPromisesResolves = [];
  1457. var numPages = this.pdfViewer.pagesCount;
  1458. for (var i = 0; i < numPages; i++) {
  1459. this.extractTextPromises.push(new Promise(function (resolve) {
  1460. extractTextPromisesResolves.push(resolve);
  1461. }));
  1462. }
  1463. var self = this;
  1464. function extractPageText(pageIndex) {
  1465. self.pdfViewer.getPageTextContent(pageIndex).then(
  1466. function textContentResolved(textContent) {
  1467. var textItems = textContent.items;
  1468. var str = [];
  1469. for (var i = 0, len = textItems.length; i < len; i++) {
  1470. str.push(textItems[i].str);
  1471. }
  1472. // Store the pageContent as a string.
  1473. self.pageContents.push(str.join(''));
  1474. extractTextPromisesResolves[pageIndex](pageIndex);
  1475. if ((pageIndex + 1) < self.pdfViewer.pagesCount) {
  1476. extractPageText(pageIndex + 1);
  1477. }
  1478. }
  1479. );
  1480. }
  1481. extractPageText(0);
  1482. },
  1483. executeCommand: function PDFFindController_executeCommand(cmd, state) {
  1484. if (this.state === null || cmd !== 'findagain') {
  1485. this.dirtyMatch = true;
  1486. }
  1487. this.state = state;
  1488. this.updateUIState(FindStates.FIND_PENDING);
  1489. this.firstPagePromise.then(function() {
  1490. this.extractText();
  1491. clearTimeout(this.findTimeout);
  1492. if (cmd === 'find') {
  1493. // Only trigger the find action after 250ms of silence.
  1494. this.findTimeout = setTimeout(this.nextMatch.bind(this), 250);
  1495. } else {
  1496. this.nextMatch();
  1497. }
  1498. }.bind(this));
  1499. },
  1500. updatePage: function PDFFindController_updatePage(index) {
  1501. if (this.selected.pageIdx === index) {
  1502. // If the page is selected, scroll the page into view, which triggers
  1503. // rendering the page, which adds the textLayer. Once the textLayer is
  1504. // build, it will scroll onto the selected match.
  1505. this.pdfViewer.scrollPageIntoView(index + 1);
  1506. }
  1507. var page = this.pdfViewer.getPageView(index);
  1508. if (page.textLayer) {
  1509. page.textLayer.updateMatches();
  1510. }
  1511. },
  1512. nextMatch: function PDFFindController_nextMatch() {
  1513. var previous = this.state.findPrevious;
  1514. var currentPageIndex = this.pdfViewer.currentPageNumber - 1;
  1515. var numPages = this.pdfViewer.pagesCount;
  1516. this.active = true;
  1517. if (this.dirtyMatch) {
  1518. // Need to recalculate the matches, reset everything.
  1519. this.dirtyMatch = false;
  1520. this.selected.pageIdx = this.selected.matchIdx = -1;
  1521. this.offset.pageIdx = currentPageIndex;
  1522. this.offset.matchIdx = null;
  1523. this.hadMatch = false;
  1524. this.resumePageIdx = null;
  1525. this.pageMatches = [];
  1526. this.matchCount = 0;
  1527. var self = this;
  1528. for (var i = 0; i < numPages; i++) {
  1529. // Wipe out any previous highlighted matches.
  1530. this.updatePage(i);
  1531. // As soon as the text is extracted start finding the matches.
  1532. if (!(i in this.pendingFindMatches)) {
  1533. this.pendingFindMatches[i] = true;
  1534. this.extractTextPromises[i].then(function(pageIdx) {
  1535. delete self.pendingFindMatches[pageIdx];
  1536. self.calcFindMatch(pageIdx);
  1537. });
  1538. }
  1539. }
  1540. }
  1541. // If there's no query there's no point in searching.
  1542. if (this.state.query === '') {
  1543. this.updateUIState(FindStates.FIND_FOUND);
  1544. return;
  1545. }
  1546. // If we're waiting on a page, we return since we can't do anything else.
  1547. if (this.resumePageIdx) {
  1548. return;
  1549. }
  1550. var offset = this.offset;
  1551. // Keep track of how many pages we should maximally iterate through.
  1552. this.pagesToSearch = numPages;
  1553. // If there's already a matchIdx that means we are iterating through a
  1554. // page's matches.
  1555. if (offset.matchIdx !== null) {
  1556. var numPageMatches = this.pageMatches[offset.pageIdx].length;
  1557. if ((!previous && offset.matchIdx + 1 < numPageMatches) ||
  1558. (previous && offset.matchIdx > 0)) {
  1559. // The simple case; we just have advance the matchIdx to select
  1560. // the next match on the page.
  1561. this.hadMatch = true;
  1562. offset.matchIdx = (previous ? offset.matchIdx - 1 :
  1563. offset.matchIdx + 1);
  1564. this.updateMatch(true);
  1565. return;
  1566. }
  1567. // We went beyond the current page's matches, so we advance to
  1568. // the next page.
  1569. this.advanceOffsetPage(previous);
  1570. }
  1571. // Start searching through the page.
  1572. this.nextPageMatch();
  1573. },
  1574. matchesReady: function PDFFindController_matchesReady(matches) {
  1575. var offset = this.offset;
  1576. var numMatches = matches.length;
  1577. var previous = this.state.findPrevious;
  1578. if (numMatches) {
  1579. // There were matches for the page, so initialize the matchIdx.
  1580. this.hadMatch = true;
  1581. offset.matchIdx = (previous ? numMatches - 1 : 0);
  1582. this.updateMatch(true);
  1583. return true;
  1584. } else {
  1585. // No matches, so attempt to search the next page.
  1586. this.advanceOffsetPage(previous);
  1587. if (offset.wrapped) {
  1588. offset.matchIdx = null;
  1589. if (this.pagesToSearch < 0) {
  1590. // No point in wrapping again, there were no matches.
  1591. this.updateMatch(false);
  1592. // while matches were not found, searching for a page
  1593. // with matches should nevertheless halt.
  1594. return true;
  1595. }
  1596. }
  1597. // Matches were not found (and searching is not done).
  1598. return false;
  1599. }
  1600. },
  1601. /**
  1602. * The method is called back from the text layer when match presentation
  1603. * is updated.
  1604. * @param {number} pageIndex - page index.
  1605. * @param {number} index - match index.
  1606. * @param {Array} elements - text layer div elements array.
  1607. * @param {number} beginIdx - start index of the div array for the match.
  1608. * @param {number} endIdx - end index of the div array for the match.
  1609. */
  1610. updateMatchPosition: function PDFFindController_updateMatchPosition(
  1611. pageIndex, index, elements, beginIdx, endIdx) {
  1612. if (this.selected.matchIdx === index &&
  1613. this.selected.pageIdx === pageIndex) {
  1614. var spot = {
  1615. top: FIND_SCROLL_OFFSET_TOP,
  1616. left: FIND_SCROLL_OFFSET_LEFT
  1617. };
  1618. scrollIntoView(elements[beginIdx], spot,
  1619. /* skipOverflowHiddenElements = */ true);
  1620. }
  1621. },
  1622. nextPageMatch: function PDFFindController_nextPageMatch() {
  1623. if (this.resumePageIdx !== null) {
  1624. console.error('There can only be one pending page.');
  1625. }
  1626. do {
  1627. var pageIdx = this.offset.pageIdx;
  1628. var matches = this.pageMatches[pageIdx];
  1629. if (!matches) {
  1630. // The matches don't exist yet for processing by "matchesReady",
  1631. // so set a resume point for when they do exist.
  1632. this.resumePageIdx = pageIdx;
  1633. break;
  1634. }
  1635. } while (!this.matchesReady(matches));
  1636. },
  1637. advanceOffsetPage: function PDFFindController_advanceOffsetPage(previous) {
  1638. var offset = this.offset;
  1639. var numPages = this.extractTextPromises.length;
  1640. offset.pageIdx = (previous ? offset.pageIdx - 1 : offset.pageIdx + 1);
  1641. offset.matchIdx = null;
  1642. this.pagesToSearch--;
  1643. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  1644. offset.pageIdx = (previous ? numPages - 1 : 0);
  1645. offset.wrapped = true;
  1646. }
  1647. },
  1648. updateMatch: function PDFFindController_updateMatch(found) {
  1649. var state = FindStates.FIND_NOTFOUND;
  1650. var wrapped = this.offset.wrapped;
  1651. this.offset.wrapped = false;
  1652. if (found) {
  1653. var previousPage = this.selected.pageIdx;
  1654. this.selected.pageIdx = this.offset.pageIdx;
  1655. this.selected.matchIdx = this.offset.matchIdx;
  1656. state = (wrapped ? FindStates.FIND_WRAPPED : FindStates.FIND_FOUND);
  1657. // Update the currently selected page to wipe out any selected matches.
  1658. if (previousPage !== -1 && previousPage !== this.selected.pageIdx) {
  1659. this.updatePage(previousPage);
  1660. }
  1661. }
  1662. this.updateUIState(state, this.state.findPrevious);
  1663. if (this.selected.pageIdx !== -1) {
  1664. this.updatePage(this.selected.pageIdx);
  1665. }
  1666. },
  1667. updateUIResultsCount:
  1668. function PDFFindController_updateUIResultsCount() {
  1669. if (this.onUpdateResultsCount) {
  1670. this.onUpdateResultsCount(this.matchCount);
  1671. }
  1672. },
  1673. updateUIState: function PDFFindController_updateUIState(state, previous) {
  1674. if (this.onUpdateState) {
  1675. this.onUpdateState(state, previous, this.matchCount);
  1676. }
  1677. }
  1678. };
  1679. return PDFFindController;
  1680. })();
  1681. exports.FindStates = FindStates;
  1682. exports.PDFFindController = PDFFindController;
  1683. }));
  1684. (function (root, factory) {
  1685. {
  1686. factory((root.pdfjsWebPDFLinkService = {}), root.pdfjsWebUIUtils);
  1687. }
  1688. }(this, function (exports, uiUtils) {
  1689. var parseQueryString = uiUtils.parseQueryString;
  1690. /**
  1691. * Performs navigation functions inside PDF, such as opening specified page,
  1692. * or destination.
  1693. * @class
  1694. * @implements {IPDFLinkService}
  1695. */
  1696. var PDFLinkService = (function () {
  1697. /**
  1698. * @constructs PDFLinkService
  1699. */
  1700. function PDFLinkService() {
  1701. this.baseUrl = null;
  1702. this.pdfDocument = null;
  1703. this.pdfViewer = null;
  1704. this.pdfHistory = null;
  1705. this._pagesRefCache = null;
  1706. }
  1707. PDFLinkService.prototype = {
  1708. setDocument: function PDFLinkService_setDocument(pdfDocument, baseUrl) {
  1709. this.baseUrl = baseUrl;
  1710. this.pdfDocument = pdfDocument;
  1711. this._pagesRefCache = Object.create(null);
  1712. },
  1713. setViewer: function PDFLinkService_setViewer(pdfViewer) {
  1714. this.pdfViewer = pdfViewer;
  1715. },
  1716. setHistory: function PDFLinkService_setHistory(pdfHistory) {
  1717. this.pdfHistory = pdfHistory;
  1718. },
  1719. /**
  1720. * @returns {number}
  1721. */
  1722. get pagesCount() {
  1723. return this.pdfDocument.numPages;
  1724. },
  1725. /**
  1726. * @returns {number}
  1727. */
  1728. get page() {
  1729. return this.pdfViewer.currentPageNumber;
  1730. },
  1731. /**
  1732. * @param {number} value
  1733. */
  1734. set page(value) {
  1735. this.pdfViewer.currentPageNumber = value;
  1736. },
  1737. /**
  1738. * @param dest - The PDF destination object.
  1739. */
  1740. navigateTo: function PDFLinkService_navigateTo(dest) {
  1741. var destString = '';
  1742. var self = this;
  1743. var goToDestination = function(destRef) {
  1744. // dest array looks like that: <page-ref> </XYZ|FitXXX> <args..>
  1745. var pageNumber = destRef instanceof Object ?
  1746. self._pagesRefCache[destRef.num + ' ' + destRef.gen + ' R'] :
  1747. (destRef + 1);
  1748. if (pageNumber) {
  1749. if (pageNumber > self.pagesCount) {
  1750. pageNumber = self.pagesCount;
  1751. }
  1752. self.pdfViewer.scrollPageIntoView(pageNumber, dest);
  1753. if (self.pdfHistory) {
  1754. // Update the browsing history.
  1755. self.pdfHistory.push({
  1756. dest: dest,
  1757. hash: destString,
  1758. page: pageNumber
  1759. });
  1760. }
  1761. } else {
  1762. self.pdfDocument.getPageIndex(destRef).then(function (pageIndex) {
  1763. var pageNum = pageIndex + 1;
  1764. var cacheKey = destRef.num + ' ' + destRef.gen + ' R';
  1765. self._pagesRefCache[cacheKey] = pageNum;
  1766. goToDestination(destRef);
  1767. });
  1768. }
  1769. };
  1770. var destinationPromise;
  1771. if (typeof dest === 'string') {
  1772. destString = dest;
  1773. destinationPromise = this.pdfDocument.getDestination(dest);
  1774. } else {
  1775. destinationPromise = Promise.resolve(dest);
  1776. }
  1777. destinationPromise.then(function(destination) {
  1778. dest = destination;
  1779. if (!(destination instanceof Array)) {
  1780. return; // invalid destination
  1781. }
  1782. goToDestination(destination[0]);
  1783. });
  1784. },
  1785. /**
  1786. * @param dest - The PDF destination object.
  1787. * @returns {string} The hyperlink to the PDF object.
  1788. */
  1789. getDestinationHash: function PDFLinkService_getDestinationHash(dest) {
  1790. if (typeof dest === 'string') {
  1791. return this.getAnchorUrl('#' + escape(dest));
  1792. }
  1793. if (dest instanceof Array) {
  1794. var destRef = dest[0]; // see navigateTo method for dest format
  1795. var pageNumber = destRef instanceof Object ?
  1796. this._pagesRefCache[destRef.num + ' ' + destRef.gen + ' R'] :
  1797. (destRef + 1);
  1798. if (pageNumber) {
  1799. var pdfOpenParams = this.getAnchorUrl('#page=' + pageNumber);
  1800. var destKind = dest[1];
  1801. if (typeof destKind === 'object' && 'name' in destKind &&
  1802. destKind.name === 'XYZ') {
  1803. var scale = (dest[4] || this.pdfViewer.currentScaleValue);
  1804. var scaleNumber = parseFloat(scale);
  1805. if (scaleNumber) {
  1806. scale = scaleNumber * 100;
  1807. }
  1808. pdfOpenParams += '&zoom=' + scale;
  1809. if (dest[2] || dest[3]) {
  1810. pdfOpenParams += ',' + (dest[2] || 0) + ',' + (dest[3] || 0);
  1811. }
  1812. }
  1813. return pdfOpenParams;
  1814. }
  1815. }
  1816. return this.getAnchorUrl('');
  1817. },
  1818. /**
  1819. * Prefix the full url on anchor links to make sure that links are resolved
  1820. * relative to the current URL instead of the one defined in <base href>.
  1821. * @param {String} anchor The anchor hash, including the #.
  1822. * @returns {string} The hyperlink to the PDF object.
  1823. */
  1824. getAnchorUrl: function PDFLinkService_getAnchorUrl(anchor) {
  1825. return (this.baseUrl || '') + anchor;
  1826. },
  1827. /**
  1828. * @param {string} hash
  1829. */
  1830. setHash: function PDFLinkService_setHash(hash) {
  1831. if (hash.indexOf('=') >= 0) {
  1832. var params = parseQueryString(hash);
  1833. // borrowing syntax from "Parameters for Opening PDF Files"
  1834. if ('nameddest' in params) {
  1835. if (this.pdfHistory) {
  1836. this.pdfHistory.updateNextHashParam(params.nameddest);
  1837. }
  1838. this.navigateTo(params.nameddest);
  1839. return;
  1840. }
  1841. var pageNumber, dest;
  1842. if ('page' in params) {
  1843. pageNumber = (params.page | 0) || 1;
  1844. }
  1845. if ('zoom' in params) {
  1846. // Build the destination array.
  1847. var zoomArgs = params.zoom.split(','); // scale,left,top
  1848. var zoomArg = zoomArgs[0];
  1849. var zoomArgNumber = parseFloat(zoomArg);
  1850. if (zoomArg.indexOf('Fit') === -1) {
  1851. // If the zoomArg is a number, it has to get divided by 100. If it's
  1852. // a string, it should stay as it is.
  1853. dest = [null, { name: 'XYZ' },
  1854. zoomArgs.length > 1 ? (zoomArgs[1] | 0) : null,
  1855. zoomArgs.length > 2 ? (zoomArgs[2] | 0) : null,
  1856. (zoomArgNumber ? zoomArgNumber / 100 : zoomArg)];
  1857. } else {
  1858. if (zoomArg === 'Fit' || zoomArg === 'FitB') {
  1859. dest = [null, { name: zoomArg }];
  1860. } else if ((zoomArg === 'FitH' || zoomArg === 'FitBH') ||
  1861. (zoomArg === 'FitV' || zoomArg === 'FitBV')) {
  1862. dest = [null, { name: zoomArg },
  1863. zoomArgs.length > 1 ? (zoomArgs[1] | 0) : null];
  1864. } else if (zoomArg === 'FitR') {
  1865. if (zoomArgs.length !== 5) {
  1866. console.error('PDFLinkService_setHash: ' +
  1867. 'Not enough parameters for \'FitR\'.');
  1868. } else {
  1869. dest = [null, { name: zoomArg },
  1870. (zoomArgs[1] | 0), (zoomArgs[2] | 0),
  1871. (zoomArgs[3] | 0), (zoomArgs[4] | 0)];
  1872. }
  1873. } else {
  1874. console.error('PDFLinkService_setHash: \'' + zoomArg +
  1875. '\' is not a valid zoom value.');
  1876. }
  1877. }
  1878. }
  1879. if (dest) {
  1880. this.pdfViewer.scrollPageIntoView(pageNumber || this.page, dest);
  1881. } else if (pageNumber) {
  1882. this.page = pageNumber; // simple page
  1883. }
  1884. if ('pagemode' in params) {
  1885. var event = document.createEvent('CustomEvent');
  1886. event.initCustomEvent('pagemode', true, true, {
  1887. mode: params.pagemode,
  1888. });
  1889. this.pdfViewer.container.dispatchEvent(event);
  1890. }
  1891. } else if (/^\d+$/.test(hash)) { // page number
  1892. this.page = hash;
  1893. } else { // named destination
  1894. if (this.pdfHistory) {
  1895. this.pdfHistory.updateNextHashParam(unescape(hash));
  1896. }
  1897. this.navigateTo(unescape(hash));
  1898. }
  1899. },
  1900. /**
  1901. * @param {string} action
  1902. */
  1903. executeNamedAction: function PDFLinkService_executeNamedAction(action) {
  1904. // See PDF reference, table 8.45 - Named action
  1905. switch (action) {
  1906. case 'GoBack':
  1907. if (this.pdfHistory) {
  1908. this.pdfHistory.back();
  1909. }
  1910. break;
  1911. case 'GoForward':
  1912. if (this.pdfHistory) {
  1913. this.pdfHistory.forward();
  1914. }
  1915. break;
  1916. case 'NextPage':
  1917. this.page++;
  1918. break;
  1919. case 'PrevPage':
  1920. this.page--;
  1921. break;
  1922. case 'LastPage':
  1923. this.page = this.pagesCount;
  1924. break;
  1925. case 'FirstPage':
  1926. this.page = 1;
  1927. break;
  1928. default:
  1929. break; // No action according to spec
  1930. }
  1931. var event = document.createEvent('CustomEvent');
  1932. event.initCustomEvent('namedaction', true, true, {
  1933. action: action
  1934. });
  1935. this.pdfViewer.container.dispatchEvent(event);
  1936. },
  1937. /**
  1938. * @param {number} pageNum - page number.
  1939. * @param {Object} pageRef - reference to the page.
  1940. */
  1941. cachePageRef: function PDFLinkService_cachePageRef(pageNum, pageRef) {
  1942. var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
  1943. this._pagesRefCache[refStr] = pageNum;
  1944. }
  1945. };
  1946. return PDFLinkService;
  1947. })();
  1948. var SimpleLinkService = (function SimpleLinkServiceClosure() {
  1949. function SimpleLinkService() {}
  1950. SimpleLinkService.prototype = {
  1951. /**
  1952. * @returns {number}
  1953. */
  1954. get page() {
  1955. return 0;
  1956. },
  1957. /**
  1958. * @param {number} value
  1959. */
  1960. set page(value) {},
  1961. /**
  1962. * @param dest - The PDF destination object.
  1963. */
  1964. navigateTo: function (dest) {},
  1965. /**
  1966. * @param dest - The PDF destination object.
  1967. * @returns {string} The hyperlink to the PDF object.
  1968. */
  1969. getDestinationHash: function (dest) {
  1970. return '#';
  1971. },
  1972. /**
  1973. * @param hash - The PDF parameters/hash.
  1974. * @returns {string} The hyperlink to the PDF object.
  1975. */
  1976. getAnchorUrl: function (hash) {
  1977. return '#';
  1978. },
  1979. /**
  1980. * @param {string} hash
  1981. */
  1982. setHash: function (hash) {},
  1983. /**
  1984. * @param {string} action
  1985. */
  1986. executeNamedAction: function (action) {},
  1987. /**
  1988. * @param {number} pageNum - page number.
  1989. * @param {Object} pageRef - reference to the page.
  1990. */
  1991. cachePageRef: function (pageNum, pageRef) {}
  1992. };
  1993. return SimpleLinkService;
  1994. })();
  1995. exports.PDFLinkService = PDFLinkService;
  1996. exports.SimpleLinkService = SimpleLinkService;
  1997. }));
  1998. (function (root, factory) {
  1999. {
  2000. factory((root.pdfjsWebPDFPageView = {}), root.pdfjsWebUIUtils,
  2001. root.pdfjsWebPDFRenderingQueue, root.pdfjsWebPDFJS);
  2002. }
  2003. }(this, function (exports, uiUtils, pdfRenderingQueue, pdfjsLib) {
  2004. var CSS_UNITS = uiUtils.CSS_UNITS;
  2005. var DEFAULT_SCALE = uiUtils.DEFAULT_SCALE;
  2006. var getOutputScale = uiUtils.getOutputScale;
  2007. var approximateFraction = uiUtils.approximateFraction;
  2008. var roundToDivide = uiUtils.roundToDivide;
  2009. var RenderingStates = pdfRenderingQueue.RenderingStates;
  2010. var TEXT_LAYER_RENDER_DELAY = 200; // ms
  2011. /**
  2012. * @typedef {Object} PDFPageViewOptions
  2013. * @property {HTMLDivElement} container - The viewer element.
  2014. * @property {number} id - The page unique ID (normally its number).
  2015. * @property {number} scale - The page scale display.
  2016. * @property {PageViewport} defaultViewport - The page viewport.
  2017. * @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
  2018. * @property {IPDFTextLayerFactory} textLayerFactory
  2019. * @property {IPDFAnnotationLayerFactory} annotationLayerFactory
  2020. */
  2021. /**
  2022. * @class
  2023. * @implements {IRenderableView}
  2024. */
  2025. var PDFPageView = (function PDFPageViewClosure() {
  2026. /**
  2027. * @constructs PDFPageView
  2028. * @param {PDFPageViewOptions} options
  2029. */
  2030. function PDFPageView(options) {
  2031. var container = options.container;
  2032. var id = options.id;
  2033. var scale = options.scale;
  2034. var defaultViewport = options.defaultViewport;
  2035. var renderingQueue = options.renderingQueue;
  2036. var textLayerFactory = options.textLayerFactory;
  2037. var annotationLayerFactory = options.annotationLayerFactory;
  2038. this.id = id;
  2039. this.renderingId = 'page' + id;
  2040. this.rotation = 0;
  2041. this.scale = scale || DEFAULT_SCALE;
  2042. this.viewport = defaultViewport;
  2043. this.pdfPageRotate = defaultViewport.rotation;
  2044. this.hasRestrictedScaling = false;
  2045. this.renderingQueue = renderingQueue;
  2046. this.textLayerFactory = textLayerFactory;
  2047. this.annotationLayerFactory = annotationLayerFactory;
  2048. this.renderingState = RenderingStates.INITIAL;
  2049. this.resume = null;
  2050. this.onBeforeDraw = null;
  2051. this.onAfterDraw = null;
  2052. this.textLayer = null;
  2053. this.zoomLayer = null;
  2054. this.annotationLayer = null;
  2055. var div = document.createElement('div');
  2056. div.id = 'pageContainer' + this.id;
  2057. div.className = 'page';
  2058. div.style.width = Math.floor(this.viewport.width) + 'px';
  2059. div.style.height = Math.floor(this.viewport.height) + 'px';
  2060. div.setAttribute('data-page-number', this.id);
  2061. this.div = div;
  2062. container.appendChild(div);
  2063. }
  2064. PDFPageView.prototype = {
  2065. setPdfPage: function PDFPageView_setPdfPage(pdfPage) {
  2066. this.pdfPage = pdfPage;
  2067. this.pdfPageRotate = pdfPage.rotate;
  2068. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  2069. this.viewport = pdfPage.getViewport(this.scale * CSS_UNITS,
  2070. totalRotation);
  2071. this.stats = pdfPage.stats;
  2072. this.reset();
  2073. },
  2074. destroy: function PDFPageView_destroy() {
  2075. this.zoomLayer = null;
  2076. this.reset();
  2077. if (this.pdfPage) {
  2078. this.pdfPage.cleanup();
  2079. }
  2080. },
  2081. reset: function PDFPageView_reset(keepZoomLayer, keepAnnotations) {
  2082. if (this.renderTask) {
  2083. this.renderTask.cancel();
  2084. }
  2085. this.resume = null;
  2086. this.renderingState = RenderingStates.INITIAL;
  2087. var div = this.div;
  2088. div.style.width = Math.floor(this.viewport.width) + 'px';
  2089. div.style.height = Math.floor(this.viewport.height) + 'px';
  2090. var childNodes = div.childNodes;
  2091. var currentZoomLayerNode = (keepZoomLayer && this.zoomLayer) || null;
  2092. var currentAnnotationNode = (keepAnnotations && this.annotationLayer &&
  2093. this.annotationLayer.div) || null;
  2094. for (var i = childNodes.length - 1; i >= 0; i--) {
  2095. var node = childNodes[i];
  2096. if (currentZoomLayerNode === node || currentAnnotationNode === node) {
  2097. continue;
  2098. }
  2099. div.removeChild(node);
  2100. }
  2101. div.removeAttribute('data-loaded');
  2102. if (currentAnnotationNode) {
  2103. // Hide annotationLayer until all elements are resized
  2104. // so they are not displayed on the already-resized page
  2105. this.annotationLayer.hide();
  2106. } else {
  2107. this.annotationLayer = null;
  2108. }
  2109. if (this.canvas && !currentZoomLayerNode) {
  2110. // Zeroing the width and height causes Firefox to release graphics
  2111. // resources immediately, which can greatly reduce memory consumption.
  2112. this.canvas.width = 0;
  2113. this.canvas.height = 0;
  2114. delete this.canvas;
  2115. }
  2116. this.loadingIconDiv = document.createElement('div');
  2117. this.loadingIconDiv.className = 'loadingIcon';
  2118. div.appendChild(this.loadingIconDiv);
  2119. },
  2120. update: function PDFPageView_update(scale, rotation) {
  2121. this.scale = scale || this.scale;
  2122. if (typeof rotation !== 'undefined') {
  2123. this.rotation = rotation;
  2124. }
  2125. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  2126. this.viewport = this.viewport.clone({
  2127. scale: this.scale * CSS_UNITS,
  2128. rotation: totalRotation
  2129. });
  2130. var isScalingRestricted = false;
  2131. if (this.canvas && pdfjsLib.PDFJS.maxCanvasPixels > 0) {
  2132. var outputScale = this.outputScale;
  2133. var pixelsInViewport = this.viewport.width * this.viewport.height;
  2134. if (((Math.floor(this.viewport.width) * outputScale.sx) | 0) *
  2135. ((Math.floor(this.viewport.height) * outputScale.sy) | 0) >
  2136. pdfjsLib.PDFJS.maxCanvasPixels) {
  2137. isScalingRestricted = true;
  2138. }
  2139. }
  2140. if (this.canvas) {
  2141. if (pdfjsLib.PDFJS.useOnlyCssZoom ||
  2142. (this.hasRestrictedScaling && isScalingRestricted)) {
  2143. this.cssTransform(this.canvas, true);
  2144. var event = document.createEvent('CustomEvent');
  2145. event.initCustomEvent('pagerendered', true, true, {
  2146. pageNumber: this.id,
  2147. cssTransform: true,
  2148. });
  2149. this.div.dispatchEvent(event);
  2150. return;
  2151. }
  2152. if (!this.zoomLayer) {
  2153. this.zoomLayer = this.canvas.parentNode;
  2154. this.zoomLayer.style.position = 'absolute';
  2155. }
  2156. }
  2157. if (this.zoomLayer) {
  2158. this.cssTransform(this.zoomLayer.firstChild);
  2159. }
  2160. this.reset(/* keepZoomLayer = */ true, /* keepAnnotations = */ true);
  2161. },
  2162. /**
  2163. * Called when moved in the parent's container.
  2164. */
  2165. updatePosition: function PDFPageView_updatePosition() {
  2166. if (this.textLayer) {
  2167. this.textLayer.render(TEXT_LAYER_RENDER_DELAY);
  2168. }
  2169. },
  2170. cssTransform: function PDFPageView_transform(canvas, redrawAnnotations) {
  2171. var CustomStyle = pdfjsLib.CustomStyle;
  2172. // Scale canvas, canvas wrapper, and page container.
  2173. var width = this.viewport.width;
  2174. var height = this.viewport.height;
  2175. var div = this.div;
  2176. canvas.style.width = canvas.parentNode.style.width = div.style.width =
  2177. Math.floor(width) + 'px';
  2178. canvas.style.height = canvas.parentNode.style.height = div.style.height =
  2179. Math.floor(height) + 'px';
  2180. // The canvas may have been originally rotated, rotate relative to that.
  2181. var relativeRotation = this.viewport.rotation - canvas._viewport.rotation;
  2182. var absRotation = Math.abs(relativeRotation);
  2183. var scaleX = 1, scaleY = 1;
  2184. if (absRotation === 90 || absRotation === 270) {
  2185. // Scale x and y because of the rotation.
  2186. scaleX = height / width;
  2187. scaleY = width / height;
  2188. }
  2189. var cssTransform = 'rotate(' + relativeRotation + 'deg) ' +
  2190. 'scale(' + scaleX + ',' + scaleY + ')';
  2191. CustomStyle.setProp('transform', canvas, cssTransform);
  2192. if (this.textLayer) {
  2193. // Rotating the text layer is more complicated since the divs inside the
  2194. // the text layer are rotated.
  2195. // TODO: This could probably be simplified by drawing the text layer in
  2196. // one orientation then rotating overall.
  2197. var textLayerViewport = this.textLayer.viewport;
  2198. var textRelativeRotation = this.viewport.rotation -
  2199. textLayerViewport.rotation;
  2200. var textAbsRotation = Math.abs(textRelativeRotation);
  2201. var scale = width / textLayerViewport.width;
  2202. if (textAbsRotation === 90 || textAbsRotation === 270) {
  2203. scale = width / textLayerViewport.height;
  2204. }
  2205. var textLayerDiv = this.textLayer.textLayerDiv;
  2206. var transX, transY;
  2207. switch (textAbsRotation) {
  2208. case 0:
  2209. transX = transY = 0;
  2210. break;
  2211. case 90:
  2212. transX = 0;
  2213. transY = '-' + textLayerDiv.style.height;
  2214. break;
  2215. case 180:
  2216. transX = '-' + textLayerDiv.style.width;
  2217. transY = '-' + textLayerDiv.style.height;
  2218. break;
  2219. case 270:
  2220. transX = '-' + textLayerDiv.style.width;
  2221. transY = 0;
  2222. break;
  2223. default:
  2224. console.error('Bad rotation value.');
  2225. break;
  2226. }
  2227. CustomStyle.setProp('transform', textLayerDiv,
  2228. 'rotate(' + textAbsRotation + 'deg) ' +
  2229. 'scale(' + scale + ', ' + scale + ') ' +
  2230. 'translate(' + transX + ', ' + transY + ')');
  2231. CustomStyle.setProp('transformOrigin', textLayerDiv, '0% 0%');
  2232. }
  2233. if (redrawAnnotations && this.annotationLayer) {
  2234. this.annotationLayer.render(this.viewport, 'display');
  2235. }
  2236. },
  2237. get width() {
  2238. return this.viewport.width;
  2239. },
  2240. get height() {
  2241. return this.viewport.height;
  2242. },
  2243. getPagePoint: function PDFPageView_getPagePoint(x, y) {
  2244. return this.viewport.convertToPdfPoint(x, y);
  2245. },
  2246. draw: function PDFPageView_draw() {
  2247. if (this.renderingState !== RenderingStates.INITIAL) {
  2248. console.error('Must be in new state before drawing');
  2249. }
  2250. this.renderingState = RenderingStates.RUNNING;
  2251. var pdfPage = this.pdfPage;
  2252. var viewport = this.viewport;
  2253. var div = this.div;
  2254. // Wrap the canvas so if it has a css transform for highdpi the overflow
  2255. // will be hidden in FF.
  2256. var canvasWrapper = document.createElement('div');
  2257. canvasWrapper.style.width = div.style.width;
  2258. canvasWrapper.style.height = div.style.height;
  2259. canvasWrapper.classList.add('canvasWrapper');
  2260. var canvas = document.createElement('canvas');
  2261. canvas.id = 'page' + this.id;
  2262. // Keep the canvas hidden until the first draw callback, or until drawing
  2263. // is complete when `!this.renderingQueue`, to prevent black flickering.
  2264. canvas.setAttribute('hidden', 'hidden');
  2265. var isCanvasHidden = true;
  2266. canvasWrapper.appendChild(canvas);
  2267. if (this.annotationLayer && this.annotationLayer.div) {
  2268. // annotationLayer needs to stay on top
  2269. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  2270. } else {
  2271. div.appendChild(canvasWrapper);
  2272. }
  2273. this.canvas = canvas;
  2274. canvas.mozOpaque = true;
  2275. var ctx = canvas.getContext('2d', {alpha: false});
  2276. var outputScale = getOutputScale(ctx);
  2277. this.outputScale = outputScale;
  2278. if (pdfjsLib.PDFJS.useOnlyCssZoom) {
  2279. var actualSizeViewport = viewport.clone({scale: CSS_UNITS});
  2280. // Use a scale that will make the canvas be the original intended size
  2281. // of the page.
  2282. outputScale.sx *= actualSizeViewport.width / viewport.width;
  2283. outputScale.sy *= actualSizeViewport.height / viewport.height;
  2284. outputScale.scaled = true;
  2285. }
  2286. if (pdfjsLib.PDFJS.maxCanvasPixels > 0) {
  2287. var pixelsInViewport = viewport.width * viewport.height;
  2288. var maxScale =
  2289. Math.sqrt(pdfjsLib.PDFJS.maxCanvasPixels / pixelsInViewport);
  2290. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  2291. outputScale.sx = maxScale;
  2292. outputScale.sy = maxScale;
  2293. outputScale.scaled = true;
  2294. this.hasRestrictedScaling = true;
  2295. } else {
  2296. this.hasRestrictedScaling = false;
  2297. }
  2298. }
  2299. var sfx = approximateFraction(outputScale.sx);
  2300. var sfy = approximateFraction(outputScale.sy);
  2301. canvas.width = roundToDivide(viewport.width * outputScale.sx, sfx[0]);
  2302. canvas.height = roundToDivide(viewport.height * outputScale.sy, sfy[0]);
  2303. canvas.style.width = roundToDivide(viewport.width, sfx[1]) + 'px';
  2304. canvas.style.height = roundToDivide(viewport.height, sfy[1]) + 'px';
  2305. // Add the viewport so it's known what it was originally drawn with.
  2306. canvas._viewport = viewport;
  2307. var textLayerDiv = null;
  2308. var textLayer = null;
  2309. if (this.textLayerFactory) {
  2310. textLayerDiv = document.createElement('div');
  2311. textLayerDiv.className = 'textLayer';
  2312. textLayerDiv.style.width = canvasWrapper.style.width;
  2313. textLayerDiv.style.height = canvasWrapper.style.height;
  2314. if (this.annotationLayer && this.annotationLayer.div) {
  2315. // annotationLayer needs to stay on top
  2316. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  2317. } else {
  2318. div.appendChild(textLayerDiv);
  2319. }
  2320. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv,
  2321. this.id - 1,
  2322. this.viewport);
  2323. }
  2324. this.textLayer = textLayer;
  2325. var resolveRenderPromise, rejectRenderPromise;
  2326. var promise = new Promise(function (resolve, reject) {
  2327. resolveRenderPromise = resolve;
  2328. rejectRenderPromise = reject;
  2329. });
  2330. // Rendering area
  2331. var self = this;
  2332. function pageViewDrawCallback(error) {
  2333. // The renderTask may have been replaced by a new one, so only remove
  2334. // the reference to the renderTask if it matches the one that is
  2335. // triggering this callback.
  2336. if (renderTask === self.renderTask) {
  2337. self.renderTask = null;
  2338. }
  2339. if (error === 'cancelled') {
  2340. rejectRenderPromise(error);
  2341. return;
  2342. }
  2343. self.renderingState = RenderingStates.FINISHED;
  2344. if (isCanvasHidden) {
  2345. self.canvas.removeAttribute('hidden');
  2346. isCanvasHidden = false;
  2347. }
  2348. if (self.loadingIconDiv) {
  2349. div.removeChild(self.loadingIconDiv);
  2350. delete self.loadingIconDiv;
  2351. }
  2352. if (self.zoomLayer) {
  2353. // Zeroing the width and height causes Firefox to release graphics
  2354. // resources immediately, which can greatly reduce memory consumption.
  2355. var zoomLayerCanvas = self.zoomLayer.firstChild;
  2356. zoomLayerCanvas.width = 0;
  2357. zoomLayerCanvas.height = 0;
  2358. div.removeChild(self.zoomLayer);
  2359. self.zoomLayer = null;
  2360. }
  2361. self.error = error;
  2362. self.stats = pdfPage.stats;
  2363. if (self.onAfterDraw) {
  2364. self.onAfterDraw();
  2365. }
  2366. var event = document.createEvent('CustomEvent');
  2367. event.initCustomEvent('pagerendered', true, true, {
  2368. pageNumber: self.id,
  2369. cssTransform: false,
  2370. });
  2371. div.dispatchEvent(event);
  2372. if (!error) {
  2373. resolveRenderPromise(undefined);
  2374. } else {
  2375. rejectRenderPromise(error);
  2376. }
  2377. }
  2378. var renderContinueCallback = null;
  2379. if (this.renderingQueue) {
  2380. renderContinueCallback = function renderContinueCallback(cont) {
  2381. if (!self.renderingQueue.isHighestPriority(self)) {
  2382. self.renderingState = RenderingStates.PAUSED;
  2383. self.resume = function resumeCallback() {
  2384. self.renderingState = RenderingStates.RUNNING;
  2385. cont();
  2386. };
  2387. return;
  2388. }
  2389. if (isCanvasHidden) {
  2390. self.canvas.removeAttribute('hidden');
  2391. isCanvasHidden = false;
  2392. }
  2393. cont();
  2394. };
  2395. }
  2396. var transform = !outputScale.scaled ? null :
  2397. [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  2398. var renderContext = {
  2399. canvasContext: ctx,
  2400. transform: transform,
  2401. viewport: this.viewport,
  2402. // intent: 'default', // === 'display'
  2403. };
  2404. var renderTask = this.renderTask = this.pdfPage.render(renderContext);
  2405. renderTask.onContinue = renderContinueCallback;
  2406. this.renderTask.promise.then(
  2407. function pdfPageRenderCallback() {
  2408. pageViewDrawCallback(null);
  2409. if (textLayer) {
  2410. self.pdfPage.getTextContent({ normalizeWhitespace: true }).then(
  2411. function textContentResolved(textContent) {
  2412. textLayer.setTextContent(textContent);
  2413. textLayer.render(TEXT_LAYER_RENDER_DELAY);
  2414. }
  2415. );
  2416. }
  2417. },
  2418. function pdfPageRenderError(error) {
  2419. pageViewDrawCallback(error);
  2420. }
  2421. );
  2422. if (this.annotationLayerFactory) {
  2423. if (!this.annotationLayer) {
  2424. this.annotationLayer = this.annotationLayerFactory.
  2425. createAnnotationLayerBuilder(div, this.pdfPage);
  2426. }
  2427. this.annotationLayer.render(this.viewport, 'display');
  2428. }
  2429. div.setAttribute('data-loaded', true);
  2430. if (self.onBeforeDraw) {
  2431. self.onBeforeDraw();
  2432. }
  2433. return promise;
  2434. },
  2435. beforePrint: function PDFPageView_beforePrint(printContainer) {
  2436. var CustomStyle = pdfjsLib.CustomStyle;
  2437. var pdfPage = this.pdfPage;
  2438. var viewport = pdfPage.getViewport(1);
  2439. // Use the same hack we use for high dpi displays for printing to get
  2440. // better output until bug 811002 is fixed in FF.
  2441. var PRINT_OUTPUT_SCALE = 2;
  2442. var canvas = document.createElement('canvas');
  2443. // The logical size of the canvas.
  2444. canvas.width = Math.floor(viewport.width) * PRINT_OUTPUT_SCALE;
  2445. canvas.height = Math.floor(viewport.height) * PRINT_OUTPUT_SCALE;
  2446. // The rendered size of the canvas, relative to the size of canvasWrapper.
  2447. canvas.style.width = (PRINT_OUTPUT_SCALE * 100) + '%';
  2448. var cssScale = 'scale(' + (1 / PRINT_OUTPUT_SCALE) + ', ' +
  2449. (1 / PRINT_OUTPUT_SCALE) + ')';
  2450. CustomStyle.setProp('transform' , canvas, cssScale);
  2451. CustomStyle.setProp('transformOrigin' , canvas, '0% 0%');
  2452. var canvasWrapper = document.createElement('div');
  2453. canvasWrapper.appendChild(canvas);
  2454. printContainer.appendChild(canvasWrapper);
  2455. canvas.mozPrintCallback = function(obj) {
  2456. var ctx = obj.context;
  2457. ctx.save();
  2458. ctx.fillStyle = 'rgb(255, 255, 255)';
  2459. ctx.fillRect(0, 0, canvas.width, canvas.height);
  2460. ctx.restore();
  2461. // Used by the mozCurrentTransform polyfill in src/display/canvas.js.
  2462. ctx._transformMatrix =
  2463. [PRINT_OUTPUT_SCALE, 0, 0, PRINT_OUTPUT_SCALE, 0, 0];
  2464. ctx.scale(PRINT_OUTPUT_SCALE, PRINT_OUTPUT_SCALE);
  2465. var renderContext = {
  2466. canvasContext: ctx,
  2467. viewport: viewport,
  2468. intent: 'print'
  2469. };
  2470. pdfPage.render(renderContext).promise.then(function() {
  2471. // Tell the printEngine that rendering this canvas/page has finished.
  2472. obj.done();
  2473. }, function(error) {
  2474. console.error(error);
  2475. // Tell the printEngine that rendering this canvas/page has failed.
  2476. // This will make the print proces stop.
  2477. if ('abort' in obj) {
  2478. obj.abort();
  2479. } else {
  2480. obj.done();
  2481. }
  2482. });
  2483. };
  2484. },
  2485. };
  2486. return PDFPageView;
  2487. })();
  2488. exports.PDFPageView = PDFPageView;
  2489. }));
  2490. (function (root, factory) {
  2491. {
  2492. factory((root.pdfjsWebAnnotationLayerBuilder = {}), root.pdfjsWebUIUtils,
  2493. root.pdfjsWebPDFLinkService, root.pdfjsWebPDFJS);
  2494. }
  2495. }(this, function (exports, uiUtils, pdfLinkService, pdfjsLib) {
  2496. var mozL10n = uiUtils.mozL10n;
  2497. var SimpleLinkService = pdfLinkService.SimpleLinkService;
  2498. /**
  2499. * @typedef {Object} AnnotationLayerBuilderOptions
  2500. * @property {HTMLDivElement} pageDiv
  2501. * @property {PDFPage} pdfPage
  2502. * @property {IPDFLinkService} linkService
  2503. * @property {DownloadManager} downloadManager
  2504. */
  2505. /**
  2506. * @class
  2507. */
  2508. var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
  2509. /**
  2510. * @param {AnnotationLayerBuilderOptions} options
  2511. * @constructs AnnotationLayerBuilder
  2512. */
  2513. function AnnotationLayerBuilder(options) {
  2514. this.pageDiv = options.pageDiv;
  2515. this.pdfPage = options.pdfPage;
  2516. this.linkService = options.linkService;
  2517. this.downloadManager = options.downloadManager;
  2518. this.div = null;
  2519. }
  2520. AnnotationLayerBuilder.prototype =
  2521. /** @lends AnnotationLayerBuilder.prototype */ {
  2522. /**
  2523. * @param {PageViewport} viewport
  2524. * @param {string} intent (default value is 'display')
  2525. */
  2526. render: function AnnotationLayerBuilder_render(viewport, intent) {
  2527. var self = this;
  2528. var parameters = {
  2529. intent: (intent === undefined ? 'display' : intent),
  2530. };
  2531. this.pdfPage.getAnnotations(parameters).then(function (annotations) {
  2532. viewport = viewport.clone({ dontFlip: true });
  2533. parameters = {
  2534. viewport: viewport,
  2535. div: self.div,
  2536. annotations: annotations,
  2537. page: self.pdfPage,
  2538. linkService: self.linkService,
  2539. downloadManager: self.downloadManager
  2540. };
  2541. if (self.div) {
  2542. // If an annotationLayer already exists, refresh its children's
  2543. // transformation matrices.
  2544. pdfjsLib.AnnotationLayer.update(parameters);
  2545. } else {
  2546. // Create an annotation layer div and render the annotations
  2547. // if there is at least one annotation.
  2548. if (annotations.length === 0) {
  2549. return;
  2550. }
  2551. self.div = document.createElement('div');
  2552. self.div.className = 'annotationLayer';
  2553. self.pageDiv.appendChild(self.div);
  2554. parameters.div = self.div;
  2555. pdfjsLib.AnnotationLayer.render(parameters);
  2556. if (typeof mozL10n !== 'undefined') {
  2557. mozL10n.translate(self.div);
  2558. }
  2559. }
  2560. });
  2561. },
  2562. hide: function AnnotationLayerBuilder_hide() {
  2563. if (!this.div) {
  2564. return;
  2565. }
  2566. this.div.setAttribute('hidden', 'true');
  2567. }
  2568. };
  2569. return AnnotationLayerBuilder;
  2570. })();
  2571. /**
  2572. * @constructor
  2573. * @implements IPDFAnnotationLayerFactory
  2574. */
  2575. function DefaultAnnotationLayerFactory() {}
  2576. DefaultAnnotationLayerFactory.prototype = {
  2577. /**
  2578. * @param {HTMLDivElement} pageDiv
  2579. * @param {PDFPage} pdfPage
  2580. * @returns {AnnotationLayerBuilder}
  2581. */
  2582. createAnnotationLayerBuilder: function (pageDiv, pdfPage) {
  2583. return new AnnotationLayerBuilder({
  2584. pageDiv: pageDiv,
  2585. pdfPage: pdfPage,
  2586. linkService: new SimpleLinkService(),
  2587. });
  2588. }
  2589. };
  2590. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  2591. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  2592. }));
  2593. (function (root, factory) {
  2594. {
  2595. factory((root.pdfjsWebPDFViewer = {}), root.pdfjsWebUIUtils,
  2596. root.pdfjsWebPDFPageView, root.pdfjsWebPDFRenderingQueue,
  2597. root.pdfjsWebTextLayerBuilder, root.pdfjsWebAnnotationLayerBuilder,
  2598. root.pdfjsWebPDFLinkService, root.pdfjsWebPDFJS);
  2599. }
  2600. }(this, function (exports, uiUtils, pdfPageView, pdfRenderingQueue,
  2601. textLayerBuilder, annotationLayerBuilder, pdfLinkService,
  2602. pdfjsLib) {
  2603. var UNKNOWN_SCALE = uiUtils.UNKNOWN_SCALE;
  2604. var SCROLLBAR_PADDING = uiUtils.SCROLLBAR_PADDING;
  2605. var VERTICAL_PADDING = uiUtils.VERTICAL_PADDING;
  2606. var MAX_AUTO_SCALE = uiUtils.MAX_AUTO_SCALE;
  2607. var CSS_UNITS = uiUtils.CSS_UNITS;
  2608. var DEFAULT_SCALE = uiUtils.DEFAULT_SCALE;
  2609. var DEFAULT_SCALE_VALUE = uiUtils.DEFAULT_SCALE_VALUE;
  2610. var scrollIntoView = uiUtils.scrollIntoView;
  2611. var watchScroll = uiUtils.watchScroll;
  2612. var getVisibleElements = uiUtils.getVisibleElements;
  2613. var PDFPageView = pdfPageView.PDFPageView;
  2614. var RenderingStates = pdfRenderingQueue.RenderingStates;
  2615. var PDFRenderingQueue = pdfRenderingQueue.PDFRenderingQueue;
  2616. var TextLayerBuilder = textLayerBuilder.TextLayerBuilder;
  2617. var AnnotationLayerBuilder = annotationLayerBuilder.AnnotationLayerBuilder;
  2618. var SimpleLinkService = pdfLinkService.SimpleLinkService;
  2619. var PresentationModeState = {
  2620. UNKNOWN: 0,
  2621. NORMAL: 1,
  2622. CHANGING: 2,
  2623. FULLSCREEN: 3,
  2624. };
  2625. var DEFAULT_CACHE_SIZE = 10;
  2626. /**
  2627. * @typedef {Object} PDFViewerOptions
  2628. * @property {HTMLDivElement} container - The container for the viewer element.
  2629. * @property {HTMLDivElement} viewer - (optional) The viewer element.
  2630. * @property {IPDFLinkService} linkService - The navigation/linking service.
  2631. * @property {DownloadManager} downloadManager - (optional) The download
  2632. * manager component.
  2633. * @property {PDFRenderingQueue} renderingQueue - (optional) The rendering
  2634. * queue object.
  2635. * @property {boolean} removePageBorders - (optional) Removes the border shadow
  2636. * around the pages. The default is false.
  2637. */
  2638. /**
  2639. * Simple viewer control to display PDF content/pages.
  2640. * @class
  2641. * @implements {IRenderableView}
  2642. */
  2643. var PDFViewer = (function pdfViewer() {
  2644. function PDFPageViewBuffer(size) {
  2645. var data = [];
  2646. this.push = function cachePush(view) {
  2647. var i = data.indexOf(view);
  2648. if (i >= 0) {
  2649. data.splice(i, 1);
  2650. }
  2651. data.push(view);
  2652. if (data.length > size) {
  2653. data.shift().destroy();
  2654. }
  2655. };
  2656. this.resize = function (newSize) {
  2657. size = newSize;
  2658. while (data.length > size) {
  2659. data.shift().destroy();
  2660. }
  2661. };
  2662. }
  2663. function isSameScale(oldScale, newScale) {
  2664. if (newScale === oldScale) {
  2665. return true;
  2666. }
  2667. if (Math.abs(newScale - oldScale) < 1e-15) {
  2668. // Prevent unnecessary re-rendering of all pages when the scale
  2669. // changes only because of limited numerical precision.
  2670. return true;
  2671. }
  2672. return false;
  2673. }
  2674. /**
  2675. * @constructs PDFViewer
  2676. * @param {PDFViewerOptions} options
  2677. */
  2678. function PDFViewer(options) {
  2679. this.container = options.container;
  2680. this.viewer = options.viewer || options.container.firstElementChild;
  2681. this.linkService = options.linkService || new SimpleLinkService();
  2682. this.downloadManager = options.downloadManager || null;
  2683. this.removePageBorders = options.removePageBorders || false;
  2684. this.defaultRenderingQueue = !options.renderingQueue;
  2685. if (this.defaultRenderingQueue) {
  2686. // Custom rendering queue is not specified, using default one
  2687. this.renderingQueue = new PDFRenderingQueue();
  2688. this.renderingQueue.setViewer(this);
  2689. } else {
  2690. this.renderingQueue = options.renderingQueue;
  2691. }
  2692. this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this));
  2693. this.updateInProgress = false;
  2694. this.presentationModeState = PresentationModeState.UNKNOWN;
  2695. this._resetView();
  2696. if (this.removePageBorders) {
  2697. this.viewer.classList.add('removePageBorders');
  2698. }
  2699. }
  2700. PDFViewer.prototype = /** @lends PDFViewer.prototype */{
  2701. get pagesCount() {
  2702. return this._pages.length;
  2703. },
  2704. getPageView: function (index) {
  2705. return this._pages[index];
  2706. },
  2707. get currentPageNumber() {
  2708. return this._currentPageNumber;
  2709. },
  2710. set currentPageNumber(val) {
  2711. if (!this.pdfDocument) {
  2712. this._currentPageNumber = val;
  2713. return;
  2714. }
  2715. var event = document.createEvent('UIEvents');
  2716. event.initUIEvent('pagechange', true, true, window, 0);
  2717. event.updateInProgress = this.updateInProgress;
  2718. if (!(0 < val && val <= this.pagesCount)) {
  2719. event.pageNumber = this._currentPageNumber;
  2720. event.previousPageNumber = val;
  2721. this.container.dispatchEvent(event);
  2722. return;
  2723. }
  2724. event.previousPageNumber = this._currentPageNumber;
  2725. this._currentPageNumber = val;
  2726. event.pageNumber = val;
  2727. this.container.dispatchEvent(event);
  2728. // Check if the caller is `PDFViewer_update`, to avoid breaking scrolling.
  2729. if (this.updateInProgress) {
  2730. return;
  2731. }
  2732. this.scrollPageIntoView(val);
  2733. },
  2734. /**
  2735. * @returns {number}
  2736. */
  2737. get currentScale() {
  2738. return this._currentScale !== UNKNOWN_SCALE ? this._currentScale :
  2739. DEFAULT_SCALE;
  2740. },
  2741. /**
  2742. * @param {number} val - Scale of the pages in percents.
  2743. */
  2744. set currentScale(val) {
  2745. if (isNaN(val)) {
  2746. throw new Error('Invalid numeric scale');
  2747. }
  2748. if (!this.pdfDocument) {
  2749. this._currentScale = val;
  2750. this._currentScaleValue = val !== UNKNOWN_SCALE ? val.toString() : null;
  2751. return;
  2752. }
  2753. this._setScale(val, false);
  2754. },
  2755. /**
  2756. * @returns {string}
  2757. */
  2758. get currentScaleValue() {
  2759. return this._currentScaleValue;
  2760. },
  2761. /**
  2762. * @param val - The scale of the pages (in percent or predefined value).
  2763. */
  2764. set currentScaleValue(val) {
  2765. if (!this.pdfDocument) {
  2766. this._currentScale = isNaN(val) ? UNKNOWN_SCALE : val;
  2767. this._currentScaleValue = val;
  2768. return;
  2769. }
  2770. this._setScale(val, false);
  2771. },
  2772. /**
  2773. * @returns {number}
  2774. */
  2775. get pagesRotation() {
  2776. return this._pagesRotation;
  2777. },
  2778. /**
  2779. * @param {number} rotation - The rotation of the pages (0, 90, 180, 270).
  2780. */
  2781. set pagesRotation(rotation) {
  2782. this._pagesRotation = rotation;
  2783. for (var i = 0, l = this._pages.length; i < l; i++) {
  2784. var pageView = this._pages[i];
  2785. pageView.update(pageView.scale, rotation);
  2786. }
  2787. this._setScale(this._currentScaleValue, true);
  2788. if (this.defaultRenderingQueue) {
  2789. this.update();
  2790. }
  2791. },
  2792. /**
  2793. * @param pdfDocument {PDFDocument}
  2794. */
  2795. setDocument: function (pdfDocument) {
  2796. if (this.pdfDocument) {
  2797. this._resetView();
  2798. }
  2799. this.pdfDocument = pdfDocument;
  2800. if (!pdfDocument) {
  2801. return;
  2802. }
  2803. var pagesCount = pdfDocument.numPages;
  2804. var self = this;
  2805. var resolvePagesPromise;
  2806. var pagesPromise = new Promise(function (resolve) {
  2807. resolvePagesPromise = resolve;
  2808. });
  2809. this.pagesPromise = pagesPromise;
  2810. pagesPromise.then(function () {
  2811. var event = document.createEvent('CustomEvent');
  2812. event.initCustomEvent('pagesloaded', true, true, {
  2813. pagesCount: pagesCount
  2814. });
  2815. self.container.dispatchEvent(event);
  2816. });
  2817. var isOnePageRenderedResolved = false;
  2818. var resolveOnePageRendered = null;
  2819. var onePageRendered = new Promise(function (resolve) {
  2820. resolveOnePageRendered = resolve;
  2821. });
  2822. this.onePageRendered = onePageRendered;
  2823. var bindOnAfterAndBeforeDraw = function (pageView) {
  2824. pageView.onBeforeDraw = function pdfViewLoadOnBeforeDraw() {
  2825. // Add the page to the buffer at the start of drawing. That way it can
  2826. // be evicted from the buffer and destroyed even if we pause its
  2827. // rendering.
  2828. self._buffer.push(this);
  2829. };
  2830. // when page is painted, using the image as thumbnail base
  2831. pageView.onAfterDraw = function pdfViewLoadOnAfterDraw() {
  2832. if (!isOnePageRenderedResolved) {
  2833. isOnePageRenderedResolved = true;
  2834. resolveOnePageRendered();
  2835. }
  2836. };
  2837. };
  2838. var firstPagePromise = pdfDocument.getPage(1);
  2839. this.firstPagePromise = firstPagePromise;
  2840. // Fetch a single page so we can get a viewport that will be the default
  2841. // viewport for all pages
  2842. return firstPagePromise.then(function(pdfPage) {
  2843. var scale = this.currentScale;
  2844. var viewport = pdfPage.getViewport(scale * CSS_UNITS);
  2845. for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  2846. var textLayerFactory = null;
  2847. if (!pdfjsLib.PDFJS.disableTextLayer) {
  2848. textLayerFactory = this;
  2849. }
  2850. var pageView = new PDFPageView({
  2851. container: this.viewer,
  2852. id: pageNum,
  2853. scale: scale,
  2854. defaultViewport: viewport.clone(),
  2855. renderingQueue: this.renderingQueue,
  2856. textLayerFactory: textLayerFactory,
  2857. annotationLayerFactory: this
  2858. });
  2859. bindOnAfterAndBeforeDraw(pageView);
  2860. this._pages.push(pageView);
  2861. }
  2862. var linkService = this.linkService;
  2863. // Fetch all the pages since the viewport is needed before printing
  2864. // starts to create the correct size canvas. Wait until one page is
  2865. // rendered so we don't tie up too many resources early on.
  2866. onePageRendered.then(function () {
  2867. if (!pdfjsLib.PDFJS.disableAutoFetch) {
  2868. var getPagesLeft = pagesCount;
  2869. for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  2870. pdfDocument.getPage(pageNum).then(function (pageNum, pdfPage) {
  2871. var pageView = self._pages[pageNum - 1];
  2872. if (!pageView.pdfPage) {
  2873. pageView.setPdfPage(pdfPage);
  2874. }
  2875. linkService.cachePageRef(pageNum, pdfPage.ref);
  2876. getPagesLeft--;
  2877. if (!getPagesLeft) {
  2878. resolvePagesPromise();
  2879. }
  2880. }.bind(null, pageNum));
  2881. }
  2882. } else {
  2883. // XXX: Printing is semi-broken with auto fetch disabled.
  2884. resolvePagesPromise();
  2885. }
  2886. });
  2887. var event = document.createEvent('CustomEvent');
  2888. event.initCustomEvent('pagesinit', true, true, null);
  2889. self.container.dispatchEvent(event);
  2890. if (this.defaultRenderingQueue) {
  2891. this.update();
  2892. }
  2893. if (this.findController) {
  2894. this.findController.resolveFirstPage();
  2895. }
  2896. }.bind(this));
  2897. },
  2898. _resetView: function () {
  2899. this._pages = [];
  2900. this._currentPageNumber = 1;
  2901. this._currentScale = UNKNOWN_SCALE;
  2902. this._currentScaleValue = null;
  2903. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  2904. this._location = null;
  2905. this._pagesRotation = 0;
  2906. this._pagesRequests = [];
  2907. var container = this.viewer;
  2908. while (container.hasChildNodes()) {
  2909. container.removeChild(container.lastChild);
  2910. }
  2911. },
  2912. _scrollUpdate: function PDFViewer_scrollUpdate() {
  2913. if (this.pagesCount === 0) {
  2914. return;
  2915. }
  2916. this.update();
  2917. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  2918. this._pages[i].updatePosition();
  2919. }
  2920. },
  2921. _setScaleDispatchEvent: function pdfViewer_setScaleDispatchEvent(
  2922. newScale, newValue, preset) {
  2923. var event = document.createEvent('UIEvents');
  2924. event.initUIEvent('scalechange', true, true, window, 0);
  2925. event.scale = newScale;
  2926. if (preset) {
  2927. event.presetValue = newValue;
  2928. }
  2929. this.container.dispatchEvent(event);
  2930. },
  2931. _setScaleUpdatePages: function pdfViewer_setScaleUpdatePages(
  2932. newScale, newValue, noScroll, preset) {
  2933. this._currentScaleValue = newValue;
  2934. if (isSameScale(this._currentScale, newScale)) {
  2935. if (preset) {
  2936. this._setScaleDispatchEvent(newScale, newValue, true);
  2937. }
  2938. return;
  2939. }
  2940. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  2941. this._pages[i].update(newScale);
  2942. }
  2943. this._currentScale = newScale;
  2944. if (!noScroll) {
  2945. var page = this._currentPageNumber, dest;
  2946. if (this._location && !pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom &&
  2947. !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  2948. page = this._location.pageNumber;
  2949. dest = [null, { name: 'XYZ' }, this._location.left,
  2950. this._location.top, null];
  2951. }
  2952. this.scrollPageIntoView(page, dest);
  2953. }
  2954. this._setScaleDispatchEvent(newScale, newValue, preset);
  2955. if (this.defaultRenderingQueue) {
  2956. this.update();
  2957. }
  2958. },
  2959. _setScale: function pdfViewer_setScale(value, noScroll) {
  2960. var scale = parseFloat(value);
  2961. if (scale > 0) {
  2962. this._setScaleUpdatePages(scale, value, noScroll, false);
  2963. } else {
  2964. var currentPage = this._pages[this._currentPageNumber - 1];
  2965. if (!currentPage) {
  2966. return;
  2967. }
  2968. var hPadding = (this.isInPresentationMode || this.removePageBorders) ?
  2969. 0 : SCROLLBAR_PADDING;
  2970. var vPadding = (this.isInPresentationMode || this.removePageBorders) ?
  2971. 0 : VERTICAL_PADDING;
  2972. var pageWidthScale = (this.container.clientWidth - hPadding) /
  2973. currentPage.width * currentPage.scale;
  2974. var pageHeightScale = (this.container.clientHeight - vPadding) /
  2975. currentPage.height * currentPage.scale;
  2976. switch (value) {
  2977. case 'page-actual':
  2978. scale = 1;
  2979. break;
  2980. case 'page-width':
  2981. scale = pageWidthScale;
  2982. break;
  2983. case 'page-height':
  2984. scale = pageHeightScale;
  2985. break;
  2986. case 'page-fit':
  2987. scale = Math.min(pageWidthScale, pageHeightScale);
  2988. break;
  2989. case 'auto':
  2990. var isLandscape = (currentPage.width > currentPage.height);
  2991. // For pages in landscape mode, fit the page height to the viewer
  2992. // *unless* the page would thus become too wide to fit horizontally.
  2993. var horizontalScale = isLandscape ?
  2994. Math.min(pageHeightScale, pageWidthScale) : pageWidthScale;
  2995. scale = Math.min(MAX_AUTO_SCALE, horizontalScale);
  2996. break;
  2997. default:
  2998. console.error('pdfViewSetScale: \'' + value +
  2999. '\' is an unknown zoom value.');
  3000. return;
  3001. }
  3002. this._setScaleUpdatePages(scale, value, noScroll, true);
  3003. }
  3004. },
  3005. /**
  3006. * Scrolls page into view.
  3007. * @param {number} pageNumber
  3008. * @param {Array} dest - (optional) original PDF destination array:
  3009. * <page-ref> </XYZ|FitXXX> <args..>
  3010. */
  3011. scrollPageIntoView: function PDFViewer_scrollPageIntoView(pageNumber,
  3012. dest) {
  3013. if (!this.pdfDocument) {
  3014. return;
  3015. }
  3016. var pageView = this._pages[pageNumber - 1];
  3017. if (this.isInPresentationMode) {
  3018. if (this._currentPageNumber !== pageView.id) {
  3019. // Avoid breaking getVisiblePages in presentation mode.
  3020. this.currentPageNumber = pageView.id;
  3021. return;
  3022. }
  3023. dest = null;
  3024. // Fixes the case when PDF has different page sizes.
  3025. this._setScale(this._currentScaleValue, true);
  3026. }
  3027. if (!dest) {
  3028. scrollIntoView(pageView.div);
  3029. return;
  3030. }
  3031. var x = 0, y = 0;
  3032. var width = 0, height = 0, widthScale, heightScale;
  3033. var changeOrientation = (pageView.rotation % 180 === 0 ? false : true);
  3034. var pageWidth = (changeOrientation ? pageView.height : pageView.width) /
  3035. pageView.scale / CSS_UNITS;
  3036. var pageHeight = (changeOrientation ? pageView.width : pageView.height) /
  3037. pageView.scale / CSS_UNITS;
  3038. var scale = 0;
  3039. switch (dest[1].name) {
  3040. case 'XYZ':
  3041. x = dest[2];
  3042. y = dest[3];
  3043. scale = dest[4];
  3044. // If x and/or y coordinates are not supplied, default to
  3045. // _top_ left of the page (not the obvious bottom left,
  3046. // since aligning the bottom of the intended page with the
  3047. // top of the window is rarely helpful).
  3048. x = x !== null ? x : 0;
  3049. y = y !== null ? y : pageHeight;
  3050. break;
  3051. case 'Fit':
  3052. case 'FitB':
  3053. scale = 'page-fit';
  3054. break;
  3055. case 'FitH':
  3056. case 'FitBH':
  3057. y = dest[2];
  3058. scale = 'page-width';
  3059. // According to the PDF spec, section 12.3.2.2, a `null` value in the
  3060. // parameter should maintain the position relative to the new page.
  3061. if (y === null && this._location) {
  3062. x = this._location.left;
  3063. y = this._location.top;
  3064. }
  3065. break;
  3066. case 'FitV':
  3067. case 'FitBV':
  3068. x = dest[2];
  3069. width = pageWidth;
  3070. height = pageHeight;
  3071. scale = 'page-height';
  3072. break;
  3073. case 'FitR':
  3074. x = dest[2];
  3075. y = dest[3];
  3076. width = dest[4] - x;
  3077. height = dest[5] - y;
  3078. var hPadding = this.removePageBorders ? 0 : SCROLLBAR_PADDING;
  3079. var vPadding = this.removePageBorders ? 0 : VERTICAL_PADDING;
  3080. widthScale = (this.container.clientWidth - hPadding) /
  3081. width / CSS_UNITS;
  3082. heightScale = (this.container.clientHeight - vPadding) /
  3083. height / CSS_UNITS;
  3084. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  3085. break;
  3086. default:
  3087. return;
  3088. }
  3089. if (scale && scale !== this._currentScale) {
  3090. this.currentScaleValue = scale;
  3091. } else if (this._currentScale === UNKNOWN_SCALE) {
  3092. this.currentScaleValue = DEFAULT_SCALE_VALUE;
  3093. }
  3094. if (scale === 'page-fit' && !dest[4]) {
  3095. scrollIntoView(pageView.div);
  3096. return;
  3097. }
  3098. var boundingRect = [
  3099. pageView.viewport.convertToViewportPoint(x, y),
  3100. pageView.viewport.convertToViewportPoint(x + width, y + height)
  3101. ];
  3102. var left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  3103. var top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  3104. scrollIntoView(pageView.div, { left: left, top: top });
  3105. },
  3106. _updateLocation: function (firstPage) {
  3107. var currentScale = this._currentScale;
  3108. var currentScaleValue = this._currentScaleValue;
  3109. var normalizedScaleValue =
  3110. parseFloat(currentScaleValue) === currentScale ?
  3111. Math.round(currentScale * 10000) / 100 : currentScaleValue;
  3112. var pageNumber = firstPage.id;
  3113. var pdfOpenParams = '#page=' + pageNumber;
  3114. pdfOpenParams += '&zoom=' + normalizedScaleValue;
  3115. var currentPageView = this._pages[pageNumber - 1];
  3116. var container = this.container;
  3117. var topLeft = currentPageView.getPagePoint(
  3118. (container.scrollLeft - firstPage.x),
  3119. (container.scrollTop - firstPage.y));
  3120. var intLeft = Math.round(topLeft[0]);
  3121. var intTop = Math.round(topLeft[1]);
  3122. pdfOpenParams += ',' + intLeft + ',' + intTop;
  3123. this._location = {
  3124. pageNumber: pageNumber,
  3125. scale: normalizedScaleValue,
  3126. top: intTop,
  3127. left: intLeft,
  3128. pdfOpenParams: pdfOpenParams
  3129. };
  3130. },
  3131. update: function PDFViewer_update() {
  3132. var visible = this._getVisiblePages();
  3133. var visiblePages = visible.views;
  3134. if (visiblePages.length === 0) {
  3135. return;
  3136. }
  3137. this.updateInProgress = true;
  3138. var suggestedCacheSize = Math.max(DEFAULT_CACHE_SIZE,
  3139. 2 * visiblePages.length + 1);
  3140. this._buffer.resize(suggestedCacheSize);
  3141. this.renderingQueue.renderHighestPriority(visible);
  3142. var currentId = this._currentPageNumber;
  3143. var firstPage = visible.first;
  3144. for (var i = 0, ii = visiblePages.length, stillFullyVisible = false;
  3145. i < ii; ++i) {
  3146. var page = visiblePages[i];
  3147. if (page.percent < 100) {
  3148. break;
  3149. }
  3150. if (page.id === currentId) {
  3151. stillFullyVisible = true;
  3152. break;
  3153. }
  3154. }
  3155. if (!stillFullyVisible) {
  3156. currentId = visiblePages[0].id;
  3157. }
  3158. if (!this.isInPresentationMode) {
  3159. this.currentPageNumber = currentId;
  3160. }
  3161. this._updateLocation(firstPage);
  3162. this.updateInProgress = false;
  3163. var event = document.createEvent('UIEvents');
  3164. event.initUIEvent('updateviewarea', true, true, window, 0);
  3165. event.location = this._location;
  3166. this.container.dispatchEvent(event);
  3167. },
  3168. containsElement: function (element) {
  3169. return this.container.contains(element);
  3170. },
  3171. focus: function () {
  3172. this.container.focus();
  3173. },
  3174. get isInPresentationMode() {
  3175. return this.presentationModeState === PresentationModeState.FULLSCREEN;
  3176. },
  3177. get isChangingPresentationMode() {
  3178. return this.presentationModeState === PresentationModeState.CHANGING;
  3179. },
  3180. get isHorizontalScrollbarEnabled() {
  3181. return (this.isInPresentationMode ?
  3182. false : (this.container.scrollWidth > this.container.clientWidth));
  3183. },
  3184. _getVisiblePages: function () {
  3185. if (!this.isInPresentationMode) {
  3186. return getVisibleElements(this.container, this._pages, true);
  3187. } else {
  3188. // The algorithm in getVisibleElements doesn't work in all browsers and
  3189. // configurations when presentation mode is active.
  3190. var visible = [];
  3191. var currentPage = this._pages[this._currentPageNumber - 1];
  3192. visible.push({ id: currentPage.id, view: currentPage });
  3193. return { first: currentPage, last: currentPage, views: visible };
  3194. }
  3195. },
  3196. cleanup: function () {
  3197. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  3198. if (this._pages[i] &&
  3199. this._pages[i].renderingState !== RenderingStates.FINISHED) {
  3200. this._pages[i].reset();
  3201. }
  3202. }
  3203. },
  3204. /**
  3205. * @param {PDFPageView} pageView
  3206. * @returns {PDFPage}
  3207. * @private
  3208. */
  3209. _ensurePdfPageLoaded: function (pageView) {
  3210. if (pageView.pdfPage) {
  3211. return Promise.resolve(pageView.pdfPage);
  3212. }
  3213. var pageNumber = pageView.id;
  3214. if (this._pagesRequests[pageNumber]) {
  3215. return this._pagesRequests[pageNumber];
  3216. }
  3217. var promise = this.pdfDocument.getPage(pageNumber).then(
  3218. function (pdfPage) {
  3219. pageView.setPdfPage(pdfPage);
  3220. this._pagesRequests[pageNumber] = null;
  3221. return pdfPage;
  3222. }.bind(this));
  3223. this._pagesRequests[pageNumber] = promise;
  3224. return promise;
  3225. },
  3226. forceRendering: function (currentlyVisiblePages) {
  3227. var visiblePages = currentlyVisiblePages || this._getVisiblePages();
  3228. var pageView = this.renderingQueue.getHighestPriority(visiblePages,
  3229. this._pages,
  3230. this.scroll.down);
  3231. if (pageView) {
  3232. this._ensurePdfPageLoaded(pageView).then(function () {
  3233. this.renderingQueue.renderView(pageView);
  3234. }.bind(this));
  3235. return true;
  3236. }
  3237. return false;
  3238. },
  3239. getPageTextContent: function (pageIndex) {
  3240. return this.pdfDocument.getPage(pageIndex + 1).then(function (page) {
  3241. return page.getTextContent({ normalizeWhitespace: true });
  3242. });
  3243. },
  3244. /**
  3245. * @param {HTMLDivElement} textLayerDiv
  3246. * @param {number} pageIndex
  3247. * @param {PageViewport} viewport
  3248. * @returns {TextLayerBuilder}
  3249. */
  3250. createTextLayerBuilder: function (textLayerDiv, pageIndex, viewport) {
  3251. return new TextLayerBuilder({
  3252. textLayerDiv: textLayerDiv,
  3253. pageIndex: pageIndex,
  3254. viewport: viewport,
  3255. findController: this.isInPresentationMode ? null : this.findController
  3256. });
  3257. },
  3258. /**
  3259. * @param {HTMLDivElement} pageDiv
  3260. * @param {PDFPage} pdfPage
  3261. * @returns {AnnotationLayerBuilder}
  3262. */
  3263. createAnnotationLayerBuilder: function (pageDiv, pdfPage) {
  3264. return new AnnotationLayerBuilder({
  3265. pageDiv: pageDiv,
  3266. pdfPage: pdfPage,
  3267. linkService: this.linkService,
  3268. downloadManager: this.downloadManager
  3269. });
  3270. },
  3271. setFindController: function (findController) {
  3272. this.findController = findController;
  3273. },
  3274. };
  3275. return PDFViewer;
  3276. })();
  3277. exports.PresentationModeState = PresentationModeState;
  3278. exports.PDFViewer = PDFViewer;
  3279. }));
  3280. }).call(pdfViewerLibs);
  3281. var PDFJS = pdfjsLib.PDFJS;
  3282. PDFJS.PDFViewer = pdfViewerLibs.pdfjsWebPDFViewer.PDFViewer;
  3283. PDFJS.PDFPageView = pdfViewerLibs.pdfjsWebPDFPageView.PDFPageView;
  3284. PDFJS.PDFLinkService = pdfViewerLibs.pdfjsWebPDFLinkService.PDFLinkService;
  3285. PDFJS.TextLayerBuilder =
  3286. pdfViewerLibs.pdfjsWebTextLayerBuilder.TextLayerBuilder;
  3287. PDFJS.DefaultTextLayerFactory =
  3288. pdfViewerLibs.pdfjsWebTextLayerBuilder.DefaultTextLayerFactory;
  3289. PDFJS.AnnotationLayerBuilder =
  3290. pdfViewerLibs.pdfjsWebAnnotationLayerBuilder.AnnotationLayerBuilder;
  3291. PDFJS.DefaultAnnotationLayerFactory =
  3292. pdfViewerLibs.pdfjsWebAnnotationLayerBuilder.DefaultAnnotationLayerFactory;
  3293. PDFJS.PDFHistory = pdfViewerLibs.pdfjsWebPDFHistory.PDFHistory;
  3294. PDFJS.PDFFindController =
  3295. pdfViewerLibs.pdfjsWebPDFFindController.PDFFindController;
  3296. PDFJS.DownloadManager = pdfViewerLibs.pdfjsWebDownloadManager.DownloadManager;
  3297. PDFJS.ProgressBar = pdfViewerLibs.pdfjsWebUIUtils.ProgressBar;
  3298. exports.PDFJS = PDFJS;
  3299. }));