app.js 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619
  1. /* Copyright 2017 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. 'use strict';
  16. Object.defineProperty(exports, "__esModule", {
  17. value: true
  18. });
  19. exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = undefined;
  20. var _ui_utils = require('./ui_utils');
  21. var _pdf = require('../pdf');
  22. var _pdf_cursor_tools = require('./pdf_cursor_tools');
  23. var _pdf_rendering_queue = require('./pdf_rendering_queue');
  24. var _pdf_sidebar = require('./pdf_sidebar');
  25. var _pdf_viewer = require('./pdf_viewer');
  26. var _dom_events = require('./dom_events');
  27. var _overlay_manager = require('./overlay_manager');
  28. var _password_prompt = require('./password_prompt');
  29. var _pdf_attachment_viewer = require('./pdf_attachment_viewer');
  30. var _pdf_document_properties = require('./pdf_document_properties');
  31. var _pdf_find_bar = require('./pdf_find_bar');
  32. var _pdf_find_controller = require('./pdf_find_controller');
  33. var _pdf_history = require('./pdf_history');
  34. var _pdf_link_service = require('./pdf_link_service');
  35. var _pdf_outline_viewer = require('./pdf_outline_viewer');
  36. var _pdf_presentation_mode = require('./pdf_presentation_mode');
  37. var _pdf_thumbnail_viewer = require('./pdf_thumbnail_viewer');
  38. var _secondary_toolbar = require('./secondary_toolbar');
  39. var _toolbar = require('./toolbar');
  40. var _view_history = require('./view_history');
  41. var DEFAULT_SCALE_DELTA = 1.1;
  42. var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  43. function configure(PDFJS) {
  44. PDFJS.imageResourcesPath = './images/';
  45. PDFJS.workerSrc = '../build/pdf.worker.js';
  46. PDFJS.cMapUrl = '../web/cmaps/';
  47. PDFJS.cMapPacked = true;
  48. }
  49. var DefaultExternalServices = {
  50. updateFindControlState: function updateFindControlState(data) {},
  51. initPassiveLoading: function initPassiveLoading(callbacks) {},
  52. fallback: function fallback(data, callback) {},
  53. reportTelemetry: function reportTelemetry(data) {},
  54. createDownloadManager: function createDownloadManager() {
  55. throw new Error('Not implemented: createDownloadManager');
  56. },
  57. createPreferences: function createPreferences() {
  58. throw new Error('Not implemented: createPreferences');
  59. },
  60. supportsIntegratedFind: false,
  61. supportsDocumentFonts: true,
  62. supportsDocumentColors: true,
  63. supportedMouseWheelZoomModifierKeys: {
  64. ctrlKey: true,
  65. metaKey: true
  66. }
  67. };
  68. var PDFViewerApplication = {
  69. initialBookmark: document.location.hash.substring(1),
  70. initialDestination: null,
  71. initialized: false,
  72. fellback: false,
  73. appConfig: null,
  74. pdfDocument: null,
  75. pdfLoadingTask: null,
  76. printService: null,
  77. pdfViewer: null,
  78. pdfThumbnailViewer: null,
  79. pdfRenderingQueue: null,
  80. pdfPresentationMode: null,
  81. pdfDocumentProperties: null,
  82. pdfLinkService: null,
  83. pdfHistory: null,
  84. pdfSidebar: null,
  85. pdfOutlineViewer: null,
  86. pdfAttachmentViewer: null,
  87. pdfCursorTools: null,
  88. store: null,
  89. downloadManager: null,
  90. overlayManager: null,
  91. preferences: null,
  92. toolbar: null,
  93. secondaryToolbar: null,
  94. eventBus: null,
  95. l10n: null,
  96. pageRotation: 0,
  97. isInitialViewSet: false,
  98. viewerPrefs: {
  99. sidebarViewOnLoad: _pdf_sidebar.SidebarView.NONE,
  100. pdfBugEnabled: false,
  101. showPreviousViewOnLoad: true,
  102. defaultZoomValue: '',
  103. disablePageLabels: false,
  104. renderer: 'canvas',
  105. enhanceTextSelection: false,
  106. renderInteractiveForms: false,
  107. enablePrintAutoRotate: false
  108. },
  109. isViewerEmbedded: window.parent !== window,
  110. url: '',
  111. baseUrl: '',
  112. externalServices: DefaultExternalServices,
  113. initialize: function pdfViewInitialize(appConfig) {
  114. var _this = this;
  115. this.preferences = this.externalServices.createPreferences();
  116. configure(_pdf.PDFJS);
  117. this.appConfig = appConfig;
  118. return this._readPreferences().then(function () {
  119. return _this._initializeL10n();
  120. }).then(function () {
  121. return _this._initializeViewerComponents();
  122. }).then(function () {
  123. _this.bindEvents();
  124. _this.bindWindowEvents();
  125. var appContainer = appConfig.appContainer || document.documentElement;
  126. _this.l10n.translate(appContainer).then(function () {
  127. _this.eventBus.dispatch('localized');
  128. });
  129. if (_this.isViewerEmbedded && !_pdf.PDFJS.isExternalLinkTargetSet()) {
  130. _pdf.PDFJS.externalLinkTarget = _pdf.PDFJS.LinkTarget.TOP;
  131. }
  132. _this.initialized = true;
  133. });
  134. },
  135. _readPreferences: function _readPreferences() {
  136. var preferences = this.preferences,
  137. viewerPrefs = this.viewerPrefs;
  138. return Promise.all([preferences.get('enableWebGL').then(function resolved(value) {
  139. _pdf.PDFJS.disableWebGL = !value;
  140. }), preferences.get('sidebarViewOnLoad').then(function resolved(value) {
  141. viewerPrefs['sidebarViewOnLoad'] = value;
  142. }), preferences.get('pdfBugEnabled').then(function resolved(value) {
  143. viewerPrefs['pdfBugEnabled'] = value;
  144. }), preferences.get('showPreviousViewOnLoad').then(function resolved(value) {
  145. viewerPrefs['showPreviousViewOnLoad'] = value;
  146. }), preferences.get('defaultZoomValue').then(function resolved(value) {
  147. viewerPrefs['defaultZoomValue'] = value;
  148. }), preferences.get('enhanceTextSelection').then(function resolved(value) {
  149. viewerPrefs['enhanceTextSelection'] = value;
  150. }), preferences.get('disableTextLayer').then(function resolved(value) {
  151. if (_pdf.PDFJS.disableTextLayer === true) {
  152. return;
  153. }
  154. _pdf.PDFJS.disableTextLayer = value;
  155. }), preferences.get('disableRange').then(function resolved(value) {
  156. if (_pdf.PDFJS.disableRange === true) {
  157. return;
  158. }
  159. _pdf.PDFJS.disableRange = value;
  160. }), preferences.get('disableStream').then(function resolved(value) {
  161. if (_pdf.PDFJS.disableStream === true) {
  162. return;
  163. }
  164. _pdf.PDFJS.disableStream = value;
  165. }), preferences.get('disableAutoFetch').then(function resolved(value) {
  166. _pdf.PDFJS.disableAutoFetch = value;
  167. }), preferences.get('disableFontFace').then(function resolved(value) {
  168. if (_pdf.PDFJS.disableFontFace === true) {
  169. return;
  170. }
  171. _pdf.PDFJS.disableFontFace = value;
  172. }), preferences.get('useOnlyCssZoom').then(function resolved(value) {
  173. _pdf.PDFJS.useOnlyCssZoom = value;
  174. }), preferences.get('externalLinkTarget').then(function resolved(value) {
  175. if (_pdf.PDFJS.isExternalLinkTargetSet()) {
  176. return;
  177. }
  178. _pdf.PDFJS.externalLinkTarget = value;
  179. }), preferences.get('renderer').then(function resolved(value) {
  180. viewerPrefs['renderer'] = value;
  181. }), preferences.get('renderInteractiveForms').then(function resolved(value) {
  182. viewerPrefs['renderInteractiveForms'] = value;
  183. }), preferences.get('disablePageLabels').then(function resolved(value) {
  184. viewerPrefs['disablePageLabels'] = value;
  185. }), preferences.get('enablePrintAutoRotate').then(function resolved(value) {
  186. viewerPrefs['enablePrintAutoRotate'] = value;
  187. })]).catch(function (reason) {});
  188. },
  189. _initializeL10n: function _initializeL10n() {
  190. if (this.viewerPrefs['pdfBugEnabled']) {
  191. var hash = document.location.hash.substring(1);
  192. var hashParams = (0, _ui_utils.parseQueryString)(hash);
  193. if ('locale' in hashParams) {
  194. _pdf.PDFJS.locale = hashParams['locale'];
  195. }
  196. }
  197. this.l10n = this.externalServices.createL10n();
  198. return this.l10n.getDirection().then(function (dir) {
  199. document.getElementsByTagName('html')[0].dir = dir;
  200. });
  201. },
  202. _initializeViewerComponents: function _initializeViewerComponents() {
  203. var _this2 = this;
  204. var appConfig = this.appConfig;
  205. return new Promise(function (resolve, reject) {
  206. _this2.overlayManager = new _overlay_manager.OverlayManager();
  207. var eventBus = appConfig.eventBus || (0, _dom_events.getGlobalEventBus)();
  208. _this2.eventBus = eventBus;
  209. var pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  210. pdfRenderingQueue.onIdle = _this2.cleanup.bind(_this2);
  211. _this2.pdfRenderingQueue = pdfRenderingQueue;
  212. var pdfLinkService = new _pdf_link_service.PDFLinkService({ eventBus: eventBus });
  213. _this2.pdfLinkService = pdfLinkService;
  214. var downloadManager = _this2.externalServices.createDownloadManager();
  215. _this2.downloadManager = downloadManager;
  216. var container = appConfig.mainContainer;
  217. var viewer = appConfig.viewerContainer;
  218. _this2.pdfViewer = new _pdf_viewer.PDFViewer({
  219. container: container,
  220. viewer: viewer,
  221. eventBus: eventBus,
  222. renderingQueue: pdfRenderingQueue,
  223. linkService: pdfLinkService,
  224. downloadManager: downloadManager,
  225. renderer: _this2.viewerPrefs['renderer'],
  226. l10n: _this2.l10n,
  227. enhanceTextSelection: _this2.viewerPrefs['enhanceTextSelection'],
  228. renderInteractiveForms: _this2.viewerPrefs['renderInteractiveForms'],
  229. enablePrintAutoRotate: _this2.viewerPrefs['enablePrintAutoRotate']
  230. });
  231. pdfRenderingQueue.setViewer(_this2.pdfViewer);
  232. pdfLinkService.setViewer(_this2.pdfViewer);
  233. var thumbnailContainer = appConfig.sidebar.thumbnailView;
  234. _this2.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  235. container: thumbnailContainer,
  236. renderingQueue: pdfRenderingQueue,
  237. linkService: pdfLinkService,
  238. l10n: _this2.l10n
  239. });
  240. pdfRenderingQueue.setThumbnailViewer(_this2.pdfThumbnailViewer);
  241. _this2.pdfHistory = new _pdf_history.PDFHistory({
  242. linkService: pdfLinkService,
  243. eventBus: eventBus
  244. });
  245. pdfLinkService.setHistory(_this2.pdfHistory);
  246. _this2.findController = new _pdf_find_controller.PDFFindController({ pdfViewer: _this2.pdfViewer });
  247. _this2.findController.onUpdateResultsCount = function (matchCount) {
  248. if (_this2.supportsIntegratedFind) {
  249. return;
  250. }
  251. _this2.findBar.updateResultsCount(matchCount);
  252. };
  253. _this2.findController.onUpdateState = function (state, previous, matchCount) {
  254. if (_this2.supportsIntegratedFind) {
  255. _this2.externalServices.updateFindControlState({
  256. result: state,
  257. findPrevious: previous
  258. });
  259. } else {
  260. _this2.findBar.updateUIState(state, previous, matchCount);
  261. }
  262. };
  263. _this2.pdfViewer.setFindController(_this2.findController);
  264. var findBarConfig = Object.create(appConfig.findBar);
  265. findBarConfig.findController = _this2.findController;
  266. findBarConfig.eventBus = eventBus;
  267. _this2.findBar = new _pdf_find_bar.PDFFindBar(findBarConfig, _this2.l10n);
  268. _this2.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, _this2.overlayManager, _this2.l10n);
  269. _this2.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  270. container: container,
  271. eventBus: eventBus,
  272. preferences: _this2.preferences
  273. });
  274. _this2.toolbar = new _toolbar.Toolbar(appConfig.toolbar, container, eventBus, _this2.l10n);
  275. _this2.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  276. if (_this2.supportsFullscreen) {
  277. _this2.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  278. container: container,
  279. viewer: viewer,
  280. pdfViewer: _this2.pdfViewer,
  281. eventBus: eventBus,
  282. contextMenuItems: appConfig.fullscreen
  283. });
  284. }
  285. _this2.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, _this2.overlayManager, _this2.l10n);
  286. _this2.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  287. container: appConfig.sidebar.outlineView,
  288. eventBus: eventBus,
  289. linkService: pdfLinkService
  290. });
  291. _this2.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  292. container: appConfig.sidebar.attachmentsView,
  293. eventBus: eventBus,
  294. downloadManager: downloadManager
  295. });
  296. var sidebarConfig = Object.create(appConfig.sidebar);
  297. sidebarConfig.pdfViewer = _this2.pdfViewer;
  298. sidebarConfig.pdfThumbnailViewer = _this2.pdfThumbnailViewer;
  299. sidebarConfig.pdfOutlineViewer = _this2.pdfOutlineViewer;
  300. sidebarConfig.eventBus = eventBus;
  301. _this2.pdfSidebar = new _pdf_sidebar.PDFSidebar(sidebarConfig, _this2.l10n);
  302. _this2.pdfSidebar.onToggled = _this2.forceRendering.bind(_this2);
  303. resolve(undefined);
  304. });
  305. },
  306. run: function pdfViewRun(config) {
  307. this.initialize(config).then(webViewerInitialized);
  308. },
  309. zoomIn: function pdfViewZoomIn(ticks) {
  310. var newScale = this.pdfViewer.currentScale;
  311. do {
  312. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  313. newScale = Math.ceil(newScale * 10) / 10;
  314. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  315. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  316. this.pdfViewer.currentScaleValue = newScale;
  317. },
  318. zoomOut: function pdfViewZoomOut(ticks) {
  319. var newScale = this.pdfViewer.currentScale;
  320. do {
  321. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  322. newScale = Math.floor(newScale * 10) / 10;
  323. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  324. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  325. this.pdfViewer.currentScaleValue = newScale;
  326. },
  327. get pagesCount() {
  328. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  329. },
  330. set page(val) {
  331. this.pdfViewer.currentPageNumber = val;
  332. },
  333. get page() {
  334. return this.pdfViewer.currentPageNumber;
  335. },
  336. get printing() {
  337. return !!this.printService;
  338. },
  339. get supportsPrinting() {
  340. return PDFPrintServiceFactory.instance.supportsPrinting;
  341. },
  342. get supportsFullscreen() {
  343. var support;
  344. var doc = document.documentElement;
  345. support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
  346. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
  347. support = false;
  348. }
  349. if (support && _pdf.PDFJS.disableFullscreen === true) {
  350. support = false;
  351. }
  352. return (0, _pdf.shadow)(this, 'supportsFullscreen', support);
  353. },
  354. get supportsIntegratedFind() {
  355. return this.externalServices.supportsIntegratedFind;
  356. },
  357. get supportsDocumentFonts() {
  358. return this.externalServices.supportsDocumentFonts;
  359. },
  360. get supportsDocumentColors() {
  361. return this.externalServices.supportsDocumentColors;
  362. },
  363. get loadingBar() {
  364. var bar = new _ui_utils.ProgressBar('#loadingBar', {});
  365. return (0, _pdf.shadow)(this, 'loadingBar', bar);
  366. },
  367. get supportedMouseWheelZoomModifierKeys() {
  368. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  369. },
  370. initPassiveLoading: function pdfViewInitPassiveLoading() {
  371. throw new Error('Not implemented: initPassiveLoading');
  372. },
  373. setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
  374. this.url = url;
  375. this.baseUrl = url.split('#')[0];
  376. var title = (0, _ui_utils.getPDFFileNameFromURL)(url, '');
  377. if (!title) {
  378. try {
  379. title = decodeURIComponent((0, _pdf.getFilenameFromUrl)(url)) || url;
  380. } catch (e) {
  381. title = url;
  382. }
  383. }
  384. this.setTitle(title);
  385. },
  386. setTitle: function pdfViewSetTitle(title) {
  387. if (this.isViewerEmbedded) {
  388. return;
  389. }
  390. document.title = title;
  391. },
  392. close: function pdfViewClose() {
  393. var errorWrapper = this.appConfig.errorWrapper.container;
  394. errorWrapper.setAttribute('hidden', 'true');
  395. if (!this.pdfLoadingTask) {
  396. return Promise.resolve();
  397. }
  398. var promise = this.pdfLoadingTask.destroy();
  399. this.pdfLoadingTask = null;
  400. if (this.pdfDocument) {
  401. this.pdfDocument = null;
  402. this.pdfThumbnailViewer.setDocument(null);
  403. this.pdfViewer.setDocument(null);
  404. this.pdfLinkService.setDocument(null, null);
  405. this.pdfDocumentProperties.setDocument(null, null);
  406. }
  407. this.store = null;
  408. this.isInitialViewSet = false;
  409. this.pdfSidebar.reset();
  410. this.pdfOutlineViewer.reset();
  411. this.pdfAttachmentViewer.reset();
  412. this.findController.reset();
  413. this.findBar.reset();
  414. this.toolbar.reset();
  415. this.secondaryToolbar.reset();
  416. if (typeof PDFBug !== 'undefined') {
  417. PDFBug.cleanup();
  418. }
  419. return promise;
  420. },
  421. open: function open(file, args) {
  422. var _this3 = this;
  423. if (arguments.length > 2 || typeof args === 'number') {
  424. return Promise.reject(new Error('Call of open() with obsolete signature.'));
  425. }
  426. if (this.pdfLoadingTask) {
  427. return this.close().then(function () {
  428. _this3.preferences.reload();
  429. return _this3.open(file, args);
  430. });
  431. }
  432. var parameters = Object.create(null),
  433. scale = void 0;
  434. if (typeof file === 'string') {
  435. this.setTitleUsingUrl(file);
  436. parameters.url = file;
  437. } else if (file && 'byteLength' in file) {
  438. parameters.data = file;
  439. } else if (file.url && file.originalUrl) {
  440. this.setTitleUsingUrl(file.originalUrl);
  441. parameters.url = file.url;
  442. }
  443. if (args) {
  444. for (var prop in args) {
  445. parameters[prop] = args[prop];
  446. }
  447. if (args.scale) {
  448. scale = args.scale;
  449. }
  450. if (args.length) {
  451. this.pdfDocumentProperties.setFileSize(args.length);
  452. }
  453. }
  454. this.downloadComplete = false;
  455. var loadingTask = (0, _pdf.getDocument)(parameters);
  456. this.pdfLoadingTask = loadingTask;
  457. loadingTask.onPassword = function (updateCallback, reason) {
  458. _this3.passwordPrompt.setUpdateCallback(updateCallback, reason);
  459. _this3.passwordPrompt.open();
  460. };
  461. loadingTask.onProgress = function (_ref) {
  462. var loaded = _ref.loaded,
  463. total = _ref.total;
  464. _this3.progress(loaded / total);
  465. };
  466. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  467. return loadingTask.promise.then(function (pdfDocument) {
  468. _this3.load(pdfDocument, scale);
  469. }, function (exception) {
  470. var message = exception && exception.message;
  471. var loadingErrorMessage = void 0;
  472. if (exception instanceof _pdf.InvalidPDFException) {
  473. loadingErrorMessage = _this3.l10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
  474. } else if (exception instanceof _pdf.MissingPDFException) {
  475. loadingErrorMessage = _this3.l10n.get('missing_file_error', null, 'Missing PDF file.');
  476. } else if (exception instanceof _pdf.UnexpectedResponseException) {
  477. loadingErrorMessage = _this3.l10n.get('unexpected_response_error', null, 'Unexpected server response.');
  478. } else {
  479. loadingErrorMessage = _this3.l10n.get('loading_error', null, 'An error occurred while loading the PDF.');
  480. }
  481. return loadingErrorMessage.then(function (msg) {
  482. _this3.error(msg, { message: message });
  483. throw new Error(msg);
  484. });
  485. });
  486. },
  487. download: function pdfViewDownload() {
  488. function downloadByUrl() {
  489. downloadManager.downloadUrl(url, filename);
  490. }
  491. var url = this.baseUrl;
  492. var filename = (0, _ui_utils.getPDFFileNameFromURL)(this.url);
  493. var downloadManager = this.downloadManager;
  494. downloadManager.onerror = function (err) {
  495. PDFViewerApplication.error('PDF failed to download.');
  496. };
  497. if (!this.pdfDocument) {
  498. downloadByUrl();
  499. return;
  500. }
  501. if (!this.downloadComplete) {
  502. downloadByUrl();
  503. return;
  504. }
  505. this.pdfDocument.getData().then(function getDataSuccess(data) {
  506. var blob = (0, _pdf.createBlob)(data, 'application/pdf');
  507. downloadManager.download(blob, url, filename);
  508. }, downloadByUrl).then(null, downloadByUrl);
  509. },
  510. fallback: function pdfViewFallback(featureId) {},
  511. error: function pdfViewError(message, moreInfo) {
  512. var moreInfoText = [this.l10n.get('error_version_info', {
  513. version: _pdf.version || '?',
  514. build: _pdf.build || '?'
  515. }, 'PDF.js v{{version}} (build: {{build}})')];
  516. if (moreInfo) {
  517. moreInfoText.push(this.l10n.get('error_message', { message: moreInfo.message }, 'Message: {{message}}'));
  518. if (moreInfo.stack) {
  519. moreInfoText.push(this.l10n.get('error_stack', { stack: moreInfo.stack }, 'Stack: {{stack}}'));
  520. } else {
  521. if (moreInfo.filename) {
  522. moreInfoText.push(this.l10n.get('error_file', { file: moreInfo.filename }, 'File: {{file}}'));
  523. }
  524. if (moreInfo.lineNumber) {
  525. moreInfoText.push(this.l10n.get('error_line', { line: moreInfo.lineNumber }, 'Line: {{line}}'));
  526. }
  527. }
  528. }
  529. var errorWrapperConfig = this.appConfig.errorWrapper;
  530. var errorWrapper = errorWrapperConfig.container;
  531. errorWrapper.removeAttribute('hidden');
  532. var errorMessage = errorWrapperConfig.errorMessage;
  533. errorMessage.textContent = message;
  534. var closeButton = errorWrapperConfig.closeButton;
  535. closeButton.onclick = function () {
  536. errorWrapper.setAttribute('hidden', 'true');
  537. };
  538. var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  539. var moreInfoButton = errorWrapperConfig.moreInfoButton;
  540. var lessInfoButton = errorWrapperConfig.lessInfoButton;
  541. moreInfoButton.onclick = function () {
  542. errorMoreInfo.removeAttribute('hidden');
  543. moreInfoButton.setAttribute('hidden', 'true');
  544. lessInfoButton.removeAttribute('hidden');
  545. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
  546. };
  547. lessInfoButton.onclick = function () {
  548. errorMoreInfo.setAttribute('hidden', 'true');
  549. moreInfoButton.removeAttribute('hidden');
  550. lessInfoButton.setAttribute('hidden', 'true');
  551. };
  552. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  553. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  554. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  555. moreInfoButton.removeAttribute('hidden');
  556. lessInfoButton.setAttribute('hidden', 'true');
  557. Promise.all(moreInfoText).then(function (parts) {
  558. errorMoreInfo.value = parts.join('\n');
  559. });
  560. },
  561. progress: function pdfViewProgress(level) {
  562. var _this4 = this;
  563. var percent = Math.round(level * 100);
  564. if (percent > this.loadingBar.percent || isNaN(percent)) {
  565. this.loadingBar.percent = percent;
  566. if (_pdf.PDFJS.disableAutoFetch && percent) {
  567. if (this.disableAutoFetchLoadingBarTimeout) {
  568. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  569. this.disableAutoFetchLoadingBarTimeout = null;
  570. }
  571. this.loadingBar.show();
  572. this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
  573. _this4.loadingBar.hide();
  574. _this4.disableAutoFetchLoadingBarTimeout = null;
  575. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  576. }
  577. }
  578. },
  579. load: function load(pdfDocument, scale) {
  580. var _this5 = this;
  581. scale = scale || _ui_utils.UNKNOWN_SCALE;
  582. this.pdfDocument = pdfDocument;
  583. pdfDocument.getDownloadInfo().then(function () {
  584. _this5.downloadComplete = true;
  585. _this5.loadingBar.hide();
  586. firstPagePromise.then(function () {
  587. _this5.eventBus.dispatch('documentload', { source: _this5 });
  588. });
  589. });
  590. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  591. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  592. var id = this.documentFingerprint = pdfDocument.fingerprint;
  593. var store = this.store = new _view_history.ViewHistory(id);
  594. var baseDocumentUrl = void 0;
  595. baseDocumentUrl = null;
  596. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  597. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  598. var pdfViewer = this.pdfViewer;
  599. pdfViewer.currentScale = scale;
  600. pdfViewer.setDocument(pdfDocument);
  601. var firstPagePromise = pdfViewer.firstPagePromise;
  602. var pagesPromise = pdfViewer.pagesPromise;
  603. var onePageRendered = pdfViewer.onePageRendered;
  604. this.pageRotation = 0;
  605. var pdfThumbnailViewer = this.pdfThumbnailViewer;
  606. pdfThumbnailViewer.setDocument(pdfDocument);
  607. firstPagePromise.then(function (pdfPage) {
  608. _this5.loadingBar.setWidth(_this5.appConfig.viewerContainer);
  609. if (!_pdf.PDFJS.disableHistory && !_this5.isViewerEmbedded) {
  610. if (!_this5.viewerPrefs['showPreviousViewOnLoad']) {
  611. _this5.pdfHistory.clearHistoryState();
  612. }
  613. _this5.pdfHistory.initialize(_this5.documentFingerprint);
  614. if (_this5.pdfHistory.initialDestination) {
  615. _this5.initialDestination = _this5.pdfHistory.initialDestination;
  616. } else if (_this5.pdfHistory.initialBookmark) {
  617. _this5.initialBookmark = _this5.pdfHistory.initialBookmark;
  618. }
  619. }
  620. var initialParams = {
  621. destination: _this5.initialDestination,
  622. bookmark: _this5.initialBookmark,
  623. hash: null
  624. };
  625. var storedHash = _this5.viewerPrefs['defaultZoomValue'] ? 'zoom=' + _this5.viewerPrefs['defaultZoomValue'] : null;
  626. var sidebarView = _this5.viewerPrefs['sidebarViewOnLoad'];
  627. new Promise(function (resolve, reject) {
  628. if (!_this5.viewerPrefs['showPreviousViewOnLoad']) {
  629. resolve();
  630. return;
  631. }
  632. store.getMultiple({
  633. exists: false,
  634. page: '1',
  635. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  636. scrollLeft: '0',
  637. scrollTop: '0',
  638. sidebarView: _pdf_sidebar.SidebarView.NONE
  639. }).then(function (values) {
  640. if (!values.exists) {
  641. resolve();
  642. return;
  643. }
  644. storedHash = 'page=' + values.page + '&zoom=' + (_this5.viewerPrefs['defaultZoomValue'] || values.zoom) + ',' + values.scrollLeft + ',' + values.scrollTop;
  645. sidebarView = _this5.viewerPrefs['sidebarViewOnLoad'] || values.sidebarView | 0;
  646. resolve();
  647. }).catch(function () {
  648. resolve();
  649. });
  650. }).then(function () {
  651. _this5.setInitialView(storedHash, {
  652. sidebarView: sidebarView,
  653. scale: scale
  654. });
  655. initialParams.hash = storedHash;
  656. if (!_this5.isViewerEmbedded) {
  657. _this5.pdfViewer.focus();
  658. }
  659. return pagesPromise;
  660. }).then(function () {
  661. if (!initialParams.destination && !initialParams.bookmark && !initialParams.hash) {
  662. return;
  663. }
  664. if (_this5.hasEqualPageSizes) {
  665. return;
  666. }
  667. _this5.initialDestination = initialParams.destination;
  668. _this5.initialBookmark = initialParams.bookmark;
  669. _this5.pdfViewer.currentScaleValue = _this5.pdfViewer.currentScaleValue;
  670. _this5.setInitialView(initialParams.hash);
  671. });
  672. });
  673. pdfDocument.getPageLabels().then(function (labels) {
  674. if (!labels || _this5.viewerPrefs['disablePageLabels']) {
  675. return;
  676. }
  677. var i = 0,
  678. numLabels = labels.length;
  679. if (numLabels !== _this5.pagesCount) {
  680. console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
  681. return;
  682. }
  683. while (i < numLabels && labels[i] === (i + 1).toString()) {
  684. i++;
  685. }
  686. if (i === numLabels) {
  687. return;
  688. }
  689. pdfViewer.setPageLabels(labels);
  690. pdfThumbnailViewer.setPageLabels(labels);
  691. _this5.toolbar.setPagesCount(pdfDocument.numPages, true);
  692. _this5.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  693. });
  694. pagesPromise.then(function () {
  695. if (!_this5.supportsPrinting) {
  696. return;
  697. }
  698. pdfDocument.getJavaScript().then(function (javaScript) {
  699. if (javaScript.length) {
  700. console.warn('Warning: JavaScript is not supported');
  701. _this5.fallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
  702. }
  703. var regex = /\bprint\s*\(/;
  704. for (var i = 0, ii = javaScript.length; i < ii; i++) {
  705. var js = javaScript[i];
  706. if (js && regex.test(js)) {
  707. setTimeout(function () {
  708. window.print();
  709. });
  710. return;
  711. }
  712. }
  713. });
  714. });
  715. Promise.all([onePageRendered, _ui_utils.animationStarted]).then(function () {
  716. pdfDocument.getOutline().then(function (outline) {
  717. _this5.pdfOutlineViewer.render({ outline: outline });
  718. });
  719. pdfDocument.getAttachments().then(function (attachments) {
  720. _this5.pdfAttachmentViewer.render({ attachments: attachments });
  721. });
  722. });
  723. pdfDocument.getMetadata().then(function (_ref2) {
  724. var info = _ref2.info,
  725. metadata = _ref2.metadata;
  726. _this5.documentInfo = info;
  727. _this5.metadata = metadata;
  728. console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (_pdf.version || '-') + (!_pdf.PDFJS.disableWebGL ? ' [WebGL]' : '') + ')');
  729. var pdfTitle = void 0;
  730. if (metadata && metadata.has('dc:title')) {
  731. var title = metadata.get('dc:title');
  732. if (title !== 'Untitled') {
  733. pdfTitle = title;
  734. }
  735. }
  736. if (!pdfTitle && info && info['Title']) {
  737. pdfTitle = info['Title'];
  738. }
  739. if (pdfTitle) {
  740. _this5.setTitle(pdfTitle + ' - ' + document.title);
  741. }
  742. if (info.IsAcroFormPresent) {
  743. console.warn('Warning: AcroForm/XFA is not supported');
  744. _this5.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
  745. }
  746. });
  747. },
  748. setInitialView: function setInitialView(storedHash) {
  749. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  750. var _options$scale = options.scale,
  751. scale = _options$scale === undefined ? 0 : _options$scale,
  752. _options$sidebarView = options.sidebarView,
  753. sidebarView = _options$sidebarView === undefined ? _pdf_sidebar.SidebarView.NONE : _options$sidebarView;
  754. this.isInitialViewSet = true;
  755. this.pdfSidebar.setInitialView(sidebarView);
  756. if (this.initialDestination) {
  757. this.pdfLinkService.navigateTo(this.initialDestination);
  758. this.initialDestination = null;
  759. } else if (this.initialBookmark) {
  760. this.pdfLinkService.setHash(this.initialBookmark);
  761. this.pdfHistory.push({ hash: this.initialBookmark }, true);
  762. this.initialBookmark = null;
  763. } else if (storedHash) {
  764. this.pdfLinkService.setHash(storedHash);
  765. } else if (scale) {
  766. this.pdfViewer.currentScaleValue = scale;
  767. this.page = 1;
  768. }
  769. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  770. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  771. if (!this.pdfViewer.currentScaleValue) {
  772. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  773. }
  774. },
  775. cleanup: function pdfViewCleanup() {
  776. if (!this.pdfDocument) {
  777. return;
  778. }
  779. this.pdfViewer.cleanup();
  780. this.pdfThumbnailViewer.cleanup();
  781. if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
  782. this.pdfDocument.cleanup();
  783. }
  784. },
  785. forceRendering: function pdfViewForceRendering() {
  786. this.pdfRenderingQueue.printing = this.printing;
  787. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  788. this.pdfRenderingQueue.renderHighestPriority();
  789. },
  790. beforePrint: function pdfViewSetupBeforePrint() {
  791. var _this6 = this;
  792. if (this.printService) {
  793. return;
  794. }
  795. if (!this.supportsPrinting) {
  796. this.l10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by ' + 'this browser.').then(function (printMessage) {
  797. _this6.error(printMessage);
  798. });
  799. return;
  800. }
  801. if (!this.pdfViewer.pageViewsReady) {
  802. this.l10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.').then(function (notReadyMessage) {
  803. window.alert(notReadyMessage);
  804. });
  805. return;
  806. }
  807. var pagesOverview = this.pdfViewer.getPagesOverview();
  808. var printContainer = this.appConfig.printContainer;
  809. var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
  810. this.printService = printService;
  811. this.forceRendering();
  812. printService.layout();
  813. },
  814. get hasEqualPageSizes() {
  815. var firstPage = this.pdfViewer.getPageView(0);
  816. for (var i = 1, ii = this.pagesCount; i < ii; ++i) {
  817. var pageView = this.pdfViewer.getPageView(i);
  818. if (pageView.width !== firstPage.width || pageView.height !== firstPage.height) {
  819. return false;
  820. }
  821. }
  822. return true;
  823. },
  824. afterPrint: function pdfViewSetupAfterPrint() {
  825. if (this.printService) {
  826. this.printService.destroy();
  827. this.printService = null;
  828. }
  829. this.forceRendering();
  830. },
  831. rotatePages: function pdfViewRotatePages(delta) {
  832. var pageNumber = this.page;
  833. this.pageRotation = (this.pageRotation + 360 + delta) % 360;
  834. this.pdfViewer.pagesRotation = this.pageRotation;
  835. this.pdfThumbnailViewer.pagesRotation = this.pageRotation;
  836. this.forceRendering();
  837. this.pdfViewer.currentPageNumber = pageNumber;
  838. },
  839. requestPresentationMode: function pdfViewRequestPresentationMode() {
  840. if (!this.pdfPresentationMode) {
  841. return;
  842. }
  843. this.pdfPresentationMode.request();
  844. },
  845. bindEvents: function pdfViewBindEvents() {
  846. var eventBus = this.eventBus;
  847. eventBus.on('resize', webViewerResize);
  848. eventBus.on('hashchange', webViewerHashchange);
  849. eventBus.on('beforeprint', this.beforePrint.bind(this));
  850. eventBus.on('afterprint', this.afterPrint.bind(this));
  851. eventBus.on('pagerendered', webViewerPageRendered);
  852. eventBus.on('textlayerrendered', webViewerTextLayerRendered);
  853. eventBus.on('updateviewarea', webViewerUpdateViewarea);
  854. eventBus.on('pagechanging', webViewerPageChanging);
  855. eventBus.on('scalechanging', webViewerScaleChanging);
  856. eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
  857. eventBus.on('pagemode', webViewerPageMode);
  858. eventBus.on('namedaction', webViewerNamedAction);
  859. eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
  860. eventBus.on('presentationmode', webViewerPresentationMode);
  861. eventBus.on('openfile', webViewerOpenFile);
  862. eventBus.on('print', webViewerPrint);
  863. eventBus.on('download', webViewerDownload);
  864. eventBus.on('firstpage', webViewerFirstPage);
  865. eventBus.on('lastpage', webViewerLastPage);
  866. eventBus.on('nextpage', webViewerNextPage);
  867. eventBus.on('previouspage', webViewerPreviousPage);
  868. eventBus.on('zoomin', webViewerZoomIn);
  869. eventBus.on('zoomout', webViewerZoomOut);
  870. eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
  871. eventBus.on('scalechanged', webViewerScaleChanged);
  872. eventBus.on('rotatecw', webViewerRotateCw);
  873. eventBus.on('rotateccw', webViewerRotateCcw);
  874. eventBus.on('documentproperties', webViewerDocumentProperties);
  875. eventBus.on('find', webViewerFind);
  876. eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
  877. eventBus.on('fileinputchange', webViewerFileInputChange);
  878. },
  879. bindWindowEvents: function pdfViewBindWindowEvents() {
  880. var eventBus = this.eventBus;
  881. window.addEventListener('wheel', webViewerWheel);
  882. window.addEventListener('click', webViewerClick);
  883. window.addEventListener('keydown', webViewerKeyDown);
  884. window.addEventListener('resize', function windowResize() {
  885. eventBus.dispatch('resize');
  886. });
  887. window.addEventListener('hashchange', function windowHashChange() {
  888. eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
  889. });
  890. window.addEventListener('beforeprint', function windowBeforePrint() {
  891. eventBus.dispatch('beforeprint');
  892. });
  893. window.addEventListener('afterprint', function windowAfterPrint() {
  894. eventBus.dispatch('afterprint');
  895. });
  896. window.addEventListener('change', function windowChange(evt) {
  897. var files = evt.target.files;
  898. if (!files || files.length === 0) {
  899. return;
  900. }
  901. eventBus.dispatch('fileinputchange', { fileInput: evt.target });
  902. });
  903. }
  904. };
  905. var validateFileURL;
  906. {
  907. var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
  908. validateFileURL = function validateFileURL(file) {
  909. try {
  910. var viewerOrigin = new URL(window.location.href).origin || 'null';
  911. if (HOSTED_VIEWER_ORIGINS.indexOf(viewerOrigin) >= 0) {
  912. return;
  913. }
  914. var fileOrigin = new URL(file, window.location.href).origin;
  915. if (fileOrigin !== viewerOrigin) {
  916. throw new Error('file origin does not match viewer\'s');
  917. }
  918. } catch (e) {
  919. var message = e && e.message;
  920. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (loadingErrorMessage) {
  921. PDFViewerApplication.error(loadingErrorMessage, { message: message });
  922. });
  923. throw e;
  924. }
  925. };
  926. }
  927. function loadAndEnablePDFBug(enabledTabs) {
  928. return new Promise(function (resolve, reject) {
  929. var appConfig = PDFViewerApplication.appConfig;
  930. var script = document.createElement('script');
  931. script.src = appConfig.debuggerScriptPath;
  932. script.onload = function () {
  933. PDFBug.enable(enabledTabs);
  934. PDFBug.init({
  935. PDFJS: _pdf.PDFJS,
  936. OPS: _pdf.OPS
  937. }, appConfig.mainContainer);
  938. resolve();
  939. };
  940. script.onerror = function () {
  941. reject(new Error('Cannot load debugger at ' + script.src));
  942. };
  943. (document.getElementsByTagName('head')[0] || document.body).appendChild(script);
  944. });
  945. }
  946. function webViewerInitialized() {
  947. var appConfig = PDFViewerApplication.appConfig;
  948. var file;
  949. var queryString = document.location.search.substring(1);
  950. var params = (0, _ui_utils.parseQueryString)(queryString);
  951. file = 'file' in params ? params.file : appConfig.defaultUrl;
  952. validateFileURL(file);
  953. var waitForBeforeOpening = [];
  954. var fileInput = document.createElement('input');
  955. fileInput.id = appConfig.openFileInputName;
  956. fileInput.className = 'fileInput';
  957. fileInput.setAttribute('type', 'file');
  958. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  959. document.body.appendChild(fileInput);
  960. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  961. appConfig.toolbar.openFile.setAttribute('hidden', 'true');
  962. appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
  963. } else {
  964. fileInput.value = null;
  965. }
  966. if (PDFViewerApplication.viewerPrefs['pdfBugEnabled']) {
  967. var hash = document.location.hash.substring(1);
  968. var hashParams = (0, _ui_utils.parseQueryString)(hash);
  969. if ('disableworker' in hashParams) {
  970. _pdf.PDFJS.disableWorker = hashParams['disableworker'] === 'true';
  971. }
  972. if ('disablerange' in hashParams) {
  973. _pdf.PDFJS.disableRange = hashParams['disablerange'] === 'true';
  974. }
  975. if ('disablestream' in hashParams) {
  976. _pdf.PDFJS.disableStream = hashParams['disablestream'] === 'true';
  977. }
  978. if ('disableautofetch' in hashParams) {
  979. _pdf.PDFJS.disableAutoFetch = hashParams['disableautofetch'] === 'true';
  980. }
  981. if ('disablefontface' in hashParams) {
  982. _pdf.PDFJS.disableFontFace = hashParams['disablefontface'] === 'true';
  983. }
  984. if ('disablehistory' in hashParams) {
  985. _pdf.PDFJS.disableHistory = hashParams['disablehistory'] === 'true';
  986. }
  987. if ('webgl' in hashParams) {
  988. _pdf.PDFJS.disableWebGL = hashParams['webgl'] !== 'true';
  989. }
  990. if ('useonlycsszoom' in hashParams) {
  991. _pdf.PDFJS.useOnlyCssZoom = hashParams['useonlycsszoom'] === 'true';
  992. }
  993. if ('verbosity' in hashParams) {
  994. _pdf.PDFJS.verbosity = hashParams['verbosity'] | 0;
  995. }
  996. if ('ignorecurrentpositiononzoom' in hashParams) {
  997. _pdf.PDFJS.ignoreCurrentPositionOnZoom = hashParams['ignorecurrentpositiononzoom'] === 'true';
  998. }
  999. if ('textlayer' in hashParams) {
  1000. switch (hashParams['textlayer']) {
  1001. case 'off':
  1002. _pdf.PDFJS.disableTextLayer = true;
  1003. break;
  1004. case 'visible':
  1005. case 'shadow':
  1006. case 'hover':
  1007. var viewer = appConfig.viewerContainer;
  1008. viewer.classList.add('textLayer-' + hashParams['textlayer']);
  1009. break;
  1010. }
  1011. }
  1012. if ('pdfbug' in hashParams) {
  1013. _pdf.PDFJS.pdfBug = true;
  1014. var pdfBug = hashParams['pdfbug'];
  1015. var enabled = pdfBug.split(',');
  1016. waitForBeforeOpening.push(loadAndEnablePDFBug(enabled));
  1017. }
  1018. }
  1019. if (!PDFViewerApplication.supportsPrinting) {
  1020. appConfig.toolbar.print.classList.add('hidden');
  1021. appConfig.secondaryToolbar.printButton.classList.add('hidden');
  1022. }
  1023. if (!PDFViewerApplication.supportsFullscreen) {
  1024. appConfig.toolbar.presentationModeButton.classList.add('hidden');
  1025. appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
  1026. }
  1027. if (PDFViewerApplication.supportsIntegratedFind) {
  1028. appConfig.toolbar.viewFind.classList.add('hidden');
  1029. }
  1030. appConfig.sidebar.mainContainer.addEventListener('transitionend', function (e) {
  1031. if (e.target === this) {
  1032. PDFViewerApplication.eventBus.dispatch('resize');
  1033. }
  1034. }, true);
  1035. appConfig.sidebar.toggleButton.addEventListener('click', function () {
  1036. PDFViewerApplication.pdfSidebar.toggle();
  1037. });
  1038. Promise.all(waitForBeforeOpening).then(function () {
  1039. webViewerOpenFileViaURL(file);
  1040. }).catch(function (reason) {
  1041. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while opening.').then(function (msg) {
  1042. PDFViewerApplication.error(msg, reason);
  1043. });
  1044. });
  1045. }
  1046. var webViewerOpenFileViaURL;
  1047. {
  1048. webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
  1049. if (file && file.lastIndexOf('file:', 0) === 0) {
  1050. PDFViewerApplication.setTitleUsingUrl(file);
  1051. var xhr = new XMLHttpRequest();
  1052. xhr.onload = function () {
  1053. PDFViewerApplication.open(new Uint8Array(xhr.response));
  1054. };
  1055. try {
  1056. xhr.open('GET', file);
  1057. xhr.responseType = 'arraybuffer';
  1058. xhr.send();
  1059. } catch (e) {
  1060. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
  1061. PDFViewerApplication.error(msg, e);
  1062. });
  1063. }
  1064. return;
  1065. }
  1066. if (file) {
  1067. PDFViewerApplication.open(file);
  1068. }
  1069. };
  1070. }
  1071. function webViewerPageRendered(e) {
  1072. var pageNumber = e.pageNumber;
  1073. var pageIndex = pageNumber - 1;
  1074. var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
  1075. if (pageNumber === PDFViewerApplication.page) {
  1076. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1077. }
  1078. if (!pageView) {
  1079. return;
  1080. }
  1081. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1082. var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
  1083. thumbnailView.setImage(pageView);
  1084. }
  1085. if (_pdf.PDFJS.pdfBug && Stats.enabled && pageView.stats) {
  1086. Stats.add(pageNumber, pageView.stats);
  1087. }
  1088. if (pageView.error) {
  1089. PDFViewerApplication.l10n.get('rendering_error', null, 'An error occurred while rendering the page.').then(function (msg) {
  1090. PDFViewerApplication.error(msg, pageView.error);
  1091. });
  1092. }
  1093. }
  1094. function webViewerTextLayerRendered(e) {}
  1095. function webViewerPageMode(e) {
  1096. var mode = e.mode,
  1097. view;
  1098. switch (mode) {
  1099. case 'thumbs':
  1100. view = _pdf_sidebar.SidebarView.THUMBS;
  1101. break;
  1102. case 'bookmarks':
  1103. case 'outline':
  1104. view = _pdf_sidebar.SidebarView.OUTLINE;
  1105. break;
  1106. case 'attachments':
  1107. view = _pdf_sidebar.SidebarView.ATTACHMENTS;
  1108. break;
  1109. case 'none':
  1110. view = _pdf_sidebar.SidebarView.NONE;
  1111. break;
  1112. default:
  1113. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1114. return;
  1115. }
  1116. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1117. }
  1118. function webViewerNamedAction(e) {
  1119. var action = e.action;
  1120. switch (action) {
  1121. case 'GoToPage':
  1122. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1123. break;
  1124. case 'Find':
  1125. if (!PDFViewerApplication.supportsIntegratedFind) {
  1126. PDFViewerApplication.findBar.toggle();
  1127. }
  1128. break;
  1129. }
  1130. }
  1131. function webViewerPresentationModeChanged(e) {
  1132. var active = e.active;
  1133. var switchInProgress = e.switchInProgress;
  1134. PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _pdf_viewer.PresentationModeState.CHANGING : active ? _pdf_viewer.PresentationModeState.FULLSCREEN : _pdf_viewer.PresentationModeState.NORMAL;
  1135. }
  1136. function webViewerSidebarViewChanged(evt) {
  1137. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1138. var store = PDFViewerApplication.store;
  1139. if (store && PDFViewerApplication.isInitialViewSet) {
  1140. store.set('sidebarView', evt.view).catch(function () {});
  1141. }
  1142. }
  1143. function webViewerUpdateViewarea(evt) {
  1144. var location = evt.location,
  1145. store = PDFViewerApplication.store;
  1146. if (store && PDFViewerApplication.isInitialViewSet) {
  1147. store.setMultiple({
  1148. 'exists': true,
  1149. 'page': location.pageNumber,
  1150. 'zoom': location.scale,
  1151. 'scrollLeft': location.left,
  1152. 'scrollTop': location.top
  1153. }).catch(function () {});
  1154. }
  1155. var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1156. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1157. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1158. PDFViewerApplication.pdfHistory.updateCurrentBookmark(location.pdfOpenParams, location.pageNumber);
  1159. var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1160. var loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1161. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1162. }
  1163. function webViewerResize() {
  1164. var currentScaleValue = PDFViewerApplication.pdfViewer.currentScaleValue;
  1165. if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
  1166. PDFViewerApplication.pdfViewer.currentScaleValue = currentScaleValue;
  1167. } else if (!currentScaleValue) {
  1168. PDFViewerApplication.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1169. }
  1170. PDFViewerApplication.pdfViewer.update();
  1171. }
  1172. function webViewerHashchange(e) {
  1173. if (PDFViewerApplication.pdfHistory.isHashChangeUnlocked) {
  1174. var hash = e.hash;
  1175. if (!hash) {
  1176. return;
  1177. }
  1178. if (!PDFViewerApplication.isInitialViewSet) {
  1179. PDFViewerApplication.initialBookmark = hash;
  1180. } else {
  1181. PDFViewerApplication.pdfLinkService.setHash(hash);
  1182. }
  1183. }
  1184. }
  1185. var webViewerFileInputChange;
  1186. {
  1187. webViewerFileInputChange = function webViewerFileInputChange(e) {
  1188. var file = e.fileInput.files[0];
  1189. if (!_pdf.PDFJS.disableCreateObjectURL && typeof URL !== 'undefined' && URL.createObjectURL) {
  1190. PDFViewerApplication.open(URL.createObjectURL(file));
  1191. } else {
  1192. var fileReader = new FileReader();
  1193. fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
  1194. var buffer = evt.target.result;
  1195. var uint8Array = new Uint8Array(buffer);
  1196. PDFViewerApplication.open(uint8Array);
  1197. };
  1198. fileReader.readAsArrayBuffer(file);
  1199. }
  1200. PDFViewerApplication.setTitleUsingUrl(file.name);
  1201. var appConfig = PDFViewerApplication.appConfig;
  1202. appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
  1203. appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
  1204. appConfig.toolbar.download.setAttribute('hidden', 'true');
  1205. appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
  1206. };
  1207. }
  1208. function webViewerPresentationMode() {
  1209. PDFViewerApplication.requestPresentationMode();
  1210. }
  1211. function webViewerOpenFile() {
  1212. var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  1213. document.getElementById(openFileInputName).click();
  1214. }
  1215. function webViewerPrint() {
  1216. window.print();
  1217. }
  1218. function webViewerDownload() {
  1219. PDFViewerApplication.download();
  1220. }
  1221. function webViewerFirstPage() {
  1222. if (PDFViewerApplication.pdfDocument) {
  1223. PDFViewerApplication.page = 1;
  1224. }
  1225. }
  1226. function webViewerLastPage() {
  1227. if (PDFViewerApplication.pdfDocument) {
  1228. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1229. }
  1230. }
  1231. function webViewerNextPage() {
  1232. PDFViewerApplication.page++;
  1233. }
  1234. function webViewerPreviousPage() {
  1235. PDFViewerApplication.page--;
  1236. }
  1237. function webViewerZoomIn() {
  1238. PDFViewerApplication.zoomIn();
  1239. }
  1240. function webViewerZoomOut() {
  1241. PDFViewerApplication.zoomOut();
  1242. }
  1243. function webViewerPageNumberChanged(e) {
  1244. var pdfViewer = PDFViewerApplication.pdfViewer;
  1245. pdfViewer.currentPageLabel = e.value;
  1246. if (e.value !== pdfViewer.currentPageNumber.toString() && e.value !== pdfViewer.currentPageLabel) {
  1247. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1248. }
  1249. }
  1250. function webViewerScaleChanged(e) {
  1251. PDFViewerApplication.pdfViewer.currentScaleValue = e.value;
  1252. }
  1253. function webViewerRotateCw() {
  1254. PDFViewerApplication.rotatePages(90);
  1255. }
  1256. function webViewerRotateCcw() {
  1257. PDFViewerApplication.rotatePages(-90);
  1258. }
  1259. function webViewerDocumentProperties() {
  1260. PDFViewerApplication.pdfDocumentProperties.open();
  1261. }
  1262. function webViewerFind(e) {
  1263. PDFViewerApplication.findController.executeCommand('find' + e.type, {
  1264. query: e.query,
  1265. phraseSearch: e.phraseSearch,
  1266. caseSensitive: e.caseSensitive,
  1267. highlightAll: e.highlightAll,
  1268. findPrevious: e.findPrevious
  1269. });
  1270. }
  1271. function webViewerFindFromUrlHash(e) {
  1272. PDFViewerApplication.findController.executeCommand('find', {
  1273. query: e.query,
  1274. phraseSearch: e.phraseSearch,
  1275. caseSensitive: false,
  1276. highlightAll: true,
  1277. findPrevious: false
  1278. });
  1279. }
  1280. function webViewerScaleChanging(e) {
  1281. PDFViewerApplication.toolbar.setPageScale(e.presetValue, e.scale);
  1282. PDFViewerApplication.pdfViewer.update();
  1283. }
  1284. function webViewerPageChanging(e) {
  1285. var page = e.pageNumber;
  1286. PDFViewerApplication.toolbar.setPageNumber(page, e.pageLabel || null);
  1287. PDFViewerApplication.secondaryToolbar.setPageNumber(page);
  1288. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1289. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
  1290. }
  1291. if (_pdf.PDFJS.pdfBug && Stats.enabled) {
  1292. var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
  1293. if (pageView.stats) {
  1294. Stats.add(page, pageView.stats);
  1295. }
  1296. }
  1297. }
  1298. var zoomDisabled = false,
  1299. zoomDisabledTimeout;
  1300. function webViewerWheel(evt) {
  1301. var pdfViewer = PDFViewerApplication.pdfViewer;
  1302. if (pdfViewer.isInPresentationMode) {
  1303. return;
  1304. }
  1305. if (evt.ctrlKey || evt.metaKey) {
  1306. var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
  1307. if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
  1308. return;
  1309. }
  1310. evt.preventDefault();
  1311. if (zoomDisabled) {
  1312. return;
  1313. }
  1314. var previousScale = pdfViewer.currentScale;
  1315. var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  1316. var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
  1317. var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
  1318. if (ticks < 0) {
  1319. PDFViewerApplication.zoomOut(-ticks);
  1320. } else {
  1321. PDFViewerApplication.zoomIn(ticks);
  1322. }
  1323. var currentScale = pdfViewer.currentScale;
  1324. if (previousScale !== currentScale) {
  1325. var scaleCorrectionFactor = currentScale / previousScale - 1;
  1326. var rect = pdfViewer.container.getBoundingClientRect();
  1327. var dx = evt.clientX - rect.left;
  1328. var dy = evt.clientY - rect.top;
  1329. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  1330. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  1331. }
  1332. } else {
  1333. zoomDisabled = true;
  1334. clearTimeout(zoomDisabledTimeout);
  1335. zoomDisabledTimeout = setTimeout(function () {
  1336. zoomDisabled = false;
  1337. }, 1000);
  1338. }
  1339. }
  1340. function webViewerClick(evt) {
  1341. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  1342. return;
  1343. }
  1344. var appConfig = PDFViewerApplication.appConfig;
  1345. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  1346. PDFViewerApplication.secondaryToolbar.close();
  1347. }
  1348. }
  1349. function webViewerKeyDown(evt) {
  1350. if (PDFViewerApplication.overlayManager.active) {
  1351. return;
  1352. }
  1353. var handled = false,
  1354. ensureViewerFocused = false;
  1355. var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  1356. var pdfViewer = PDFViewerApplication.pdfViewer;
  1357. var isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
  1358. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  1359. switch (evt.keyCode) {
  1360. case 70:
  1361. if (!PDFViewerApplication.supportsIntegratedFind) {
  1362. PDFViewerApplication.findBar.open();
  1363. handled = true;
  1364. }
  1365. break;
  1366. case 71:
  1367. if (!PDFViewerApplication.supportsIntegratedFind) {
  1368. var findState = PDFViewerApplication.findController.state;
  1369. if (findState) {
  1370. PDFViewerApplication.findController.executeCommand('findagain', {
  1371. query: findState.query,
  1372. phraseSearch: findState.phraseSearch,
  1373. caseSensitive: findState.caseSensitive,
  1374. highlightAll: findState.highlightAll,
  1375. findPrevious: cmd === 5 || cmd === 12
  1376. });
  1377. }
  1378. handled = true;
  1379. }
  1380. break;
  1381. case 61:
  1382. case 107:
  1383. case 187:
  1384. case 171:
  1385. if (!isViewerInPresentationMode) {
  1386. PDFViewerApplication.zoomIn();
  1387. }
  1388. handled = true;
  1389. break;
  1390. case 173:
  1391. case 109:
  1392. case 189:
  1393. if (!isViewerInPresentationMode) {
  1394. PDFViewerApplication.zoomOut();
  1395. }
  1396. handled = true;
  1397. break;
  1398. case 48:
  1399. case 96:
  1400. if (!isViewerInPresentationMode) {
  1401. setTimeout(function () {
  1402. pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1403. });
  1404. handled = false;
  1405. }
  1406. break;
  1407. case 38:
  1408. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1409. PDFViewerApplication.page = 1;
  1410. handled = true;
  1411. ensureViewerFocused = true;
  1412. }
  1413. break;
  1414. case 40:
  1415. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1416. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1417. handled = true;
  1418. ensureViewerFocused = true;
  1419. }
  1420. break;
  1421. }
  1422. }
  1423. if (cmd === 1 || cmd === 8) {
  1424. switch (evt.keyCode) {
  1425. case 83:
  1426. PDFViewerApplication.download();
  1427. handled = true;
  1428. break;
  1429. }
  1430. }
  1431. if (cmd === 3 || cmd === 10) {
  1432. switch (evt.keyCode) {
  1433. case 80:
  1434. PDFViewerApplication.requestPresentationMode();
  1435. handled = true;
  1436. break;
  1437. case 71:
  1438. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1439. handled = true;
  1440. break;
  1441. }
  1442. }
  1443. if (handled) {
  1444. if (ensureViewerFocused && !isViewerInPresentationMode) {
  1445. pdfViewer.focus();
  1446. }
  1447. evt.preventDefault();
  1448. return;
  1449. }
  1450. var curElement = document.activeElement || document.querySelector(':focus');
  1451. var curElementTagName = curElement && curElement.tagName.toUpperCase();
  1452. if (curElementTagName === 'INPUT' || curElementTagName === 'TEXTAREA' || curElementTagName === 'SELECT') {
  1453. if (evt.keyCode !== 27) {
  1454. return;
  1455. }
  1456. }
  1457. if (cmd === 0) {
  1458. switch (evt.keyCode) {
  1459. case 38:
  1460. case 33:
  1461. case 8:
  1462. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1463. break;
  1464. }
  1465. case 37:
  1466. if (pdfViewer.isHorizontalScrollbarEnabled) {
  1467. break;
  1468. }
  1469. case 75:
  1470. case 80:
  1471. if (PDFViewerApplication.page > 1) {
  1472. PDFViewerApplication.page--;
  1473. }
  1474. handled = true;
  1475. break;
  1476. case 27:
  1477. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  1478. PDFViewerApplication.secondaryToolbar.close();
  1479. handled = true;
  1480. }
  1481. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  1482. PDFViewerApplication.findBar.close();
  1483. handled = true;
  1484. }
  1485. break;
  1486. case 40:
  1487. case 34:
  1488. case 32:
  1489. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1490. break;
  1491. }
  1492. case 39:
  1493. if (pdfViewer.isHorizontalScrollbarEnabled) {
  1494. break;
  1495. }
  1496. case 74:
  1497. case 78:
  1498. if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1499. PDFViewerApplication.page++;
  1500. }
  1501. handled = true;
  1502. break;
  1503. case 36:
  1504. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1505. PDFViewerApplication.page = 1;
  1506. handled = true;
  1507. ensureViewerFocused = true;
  1508. }
  1509. break;
  1510. case 35:
  1511. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1512. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1513. handled = true;
  1514. ensureViewerFocused = true;
  1515. }
  1516. break;
  1517. case 83:
  1518. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  1519. break;
  1520. case 72:
  1521. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  1522. break;
  1523. case 82:
  1524. PDFViewerApplication.rotatePages(90);
  1525. break;
  1526. }
  1527. }
  1528. if (cmd === 4) {
  1529. switch (evt.keyCode) {
  1530. case 32:
  1531. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1532. break;
  1533. }
  1534. if (PDFViewerApplication.page > 1) {
  1535. PDFViewerApplication.page--;
  1536. }
  1537. handled = true;
  1538. break;
  1539. case 82:
  1540. PDFViewerApplication.rotatePages(-90);
  1541. break;
  1542. }
  1543. }
  1544. if (!handled && !isViewerInPresentationMode) {
  1545. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== 'BUTTON') {
  1546. ensureViewerFocused = true;
  1547. }
  1548. }
  1549. if (cmd === 2) {
  1550. switch (evt.keyCode) {
  1551. case 37:
  1552. if (isViewerInPresentationMode) {
  1553. PDFViewerApplication.pdfHistory.back();
  1554. handled = true;
  1555. }
  1556. break;
  1557. case 39:
  1558. if (isViewerInPresentationMode) {
  1559. PDFViewerApplication.pdfHistory.forward();
  1560. handled = true;
  1561. }
  1562. break;
  1563. }
  1564. }
  1565. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  1566. pdfViewer.focus();
  1567. }
  1568. if (handled) {
  1569. evt.preventDefault();
  1570. }
  1571. }
  1572. var PDFPrintServiceFactory = {
  1573. instance: {
  1574. supportsPrinting: false,
  1575. createPrintService: function createPrintService() {
  1576. throw new Error('Not implemented: createPrintService');
  1577. }
  1578. }
  1579. };
  1580. exports.PDFViewerApplication = PDFViewerApplication;
  1581. exports.DefaultExternalServices = DefaultExternalServices;
  1582. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;