app.js 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = void 0;
  27. var _ui_utils = require("./ui_utils.js");
  28. var _app_options = require("./app_options.js");
  29. var _pdf = require("../pdf");
  30. var _pdf_cursor_tools = require("./pdf_cursor_tools.js");
  31. var _pdf_rendering_queue = require("./pdf_rendering_queue.js");
  32. var _pdf_sidebar = require("./pdf_sidebar.js");
  33. var _overlay_manager = require("./overlay_manager.js");
  34. var _password_prompt = require("./password_prompt.js");
  35. var _pdf_attachment_viewer = require("./pdf_attachment_viewer.js");
  36. var _pdf_document_properties = require("./pdf_document_properties.js");
  37. var _pdf_find_bar = require("./pdf_find_bar.js");
  38. var _pdf_find_controller = require("./pdf_find_controller.js");
  39. var _pdf_history = require("./pdf_history.js");
  40. var _pdf_layer_viewer = require("./pdf_layer_viewer.js");
  41. var _pdf_link_service = require("./pdf_link_service.js");
  42. var _pdf_outline_viewer = require("./pdf_outline_viewer.js");
  43. var _pdf_presentation_mode = require("./pdf_presentation_mode.js");
  44. var _pdf_sidebar_resizer = require("./pdf_sidebar_resizer.js");
  45. var _pdf_thumbnail_viewer = require("./pdf_thumbnail_viewer.js");
  46. var _pdf_viewer = require("./pdf_viewer.js");
  47. var _secondary_toolbar = require("./secondary_toolbar.js");
  48. var _toolbar = require("./toolbar.js");
  49. var _viewer_compatibility = require("./viewer_compatibility.js");
  50. var _view_history = require("./view_history.js");
  51. const DEFAULT_SCALE_DELTA = 1.1;
  52. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  53. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  54. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  55. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  56. const ViewOnLoad = {
  57. UNKNOWN: -1,
  58. PREVIOUS: 0,
  59. INITIAL: 1
  60. };
  61. const KNOWN_VERSIONS = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3"];
  62. const KNOWN_GENERATORS = ["acrobat distiller", "acrobat pdfwriter", "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf"];
  63. class DefaultExternalServices {
  64. constructor() {
  65. throw new Error("Cannot initialize DefaultExternalServices.");
  66. }
  67. static updateFindControlState(data) {}
  68. static updateFindMatchesCount(data) {}
  69. static initPassiveLoading(callbacks) {}
  70. static fallback(data, callback) {}
  71. static reportTelemetry(data) {}
  72. static createDownloadManager(options) {
  73. throw new Error("Not implemented: createDownloadManager");
  74. }
  75. static createPreferences() {
  76. throw new Error("Not implemented: createPreferences");
  77. }
  78. static createL10n(options) {
  79. throw new Error("Not implemented: createL10n");
  80. }
  81. static get supportsIntegratedFind() {
  82. return (0, _pdf.shadow)(this, "supportsIntegratedFind", false);
  83. }
  84. static get supportsDocumentFonts() {
  85. return (0, _pdf.shadow)(this, "supportsDocumentFonts", true);
  86. }
  87. static get supportedMouseWheelZoomModifierKeys() {
  88. return (0, _pdf.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  89. ctrlKey: true,
  90. metaKey: true
  91. });
  92. }
  93. static get isInAutomation() {
  94. return (0, _pdf.shadow)(this, "isInAutomation", false);
  95. }
  96. }
  97. exports.DefaultExternalServices = DefaultExternalServices;
  98. const PDFViewerApplication = {
  99. initialBookmark: document.location.hash.substring(1),
  100. _initializedCapability: (0, _pdf.createPromiseCapability)(),
  101. fellback: false,
  102. appConfig: null,
  103. pdfDocument: null,
  104. pdfLoadingTask: null,
  105. printService: null,
  106. pdfViewer: null,
  107. pdfThumbnailViewer: null,
  108. pdfRenderingQueue: null,
  109. pdfPresentationMode: null,
  110. pdfDocumentProperties: null,
  111. pdfLinkService: null,
  112. pdfHistory: null,
  113. pdfSidebar: null,
  114. pdfSidebarResizer: null,
  115. pdfOutlineViewer: null,
  116. pdfAttachmentViewer: null,
  117. pdfLayerViewer: null,
  118. pdfCursorTools: null,
  119. store: null,
  120. downloadManager: null,
  121. overlayManager: null,
  122. preferences: null,
  123. toolbar: null,
  124. secondaryToolbar: null,
  125. eventBus: null,
  126. l10n: null,
  127. isInitialViewSet: false,
  128. downloadComplete: false,
  129. isViewerEmbedded: window.parent !== window,
  130. url: "",
  131. baseUrl: "",
  132. externalServices: DefaultExternalServices,
  133. _boundEvents: {},
  134. contentDispositionFilename: null,
  135. triggerDelayedFallback: null,
  136. _saveInProgress: false,
  137. _wheelUnusedTicks: 0,
  138. async initialize(appConfig) {
  139. this.preferences = this.externalServices.createPreferences();
  140. this.appConfig = appConfig;
  141. await this._readPreferences();
  142. await this._parseHashParameters();
  143. await this._initializeL10n();
  144. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf.LinkTarget.NONE) {
  145. _app_options.AppOptions.set("externalLinkTarget", _pdf.LinkTarget.TOP);
  146. }
  147. await this._initializeViewerComponents();
  148. this.bindEvents();
  149. this.bindWindowEvents();
  150. const appContainer = appConfig.appContainer || document.documentElement;
  151. this.l10n.translate(appContainer).then(() => {
  152. this.eventBus.dispatch("localized", {
  153. source: this
  154. });
  155. });
  156. this._initializedCapability.resolve();
  157. },
  158. async _readPreferences() {
  159. if (_app_options.AppOptions.get("disablePreferences")) {
  160. return;
  161. }
  162. try {
  163. const prefs = await this.preferences.getAll();
  164. for (const name in prefs) {
  165. _app_options.AppOptions.set(name, prefs[name]);
  166. }
  167. } catch (reason) {
  168. console.error(`_readPreferences: "${reason.message}".`);
  169. }
  170. },
  171. async _parseHashParameters() {
  172. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  173. return undefined;
  174. }
  175. const hash = document.location.hash.substring(1);
  176. if (!hash) {
  177. return undefined;
  178. }
  179. const hashParams = (0, _ui_utils.parseQueryString)(hash),
  180. waitOn = [];
  181. if ("disableworker" in hashParams && hashParams.disableworker === "true") {
  182. waitOn.push(loadFakeWorker());
  183. }
  184. if ("disablerange" in hashParams) {
  185. _app_options.AppOptions.set("disableRange", hashParams.disablerange === "true");
  186. }
  187. if ("disablestream" in hashParams) {
  188. _app_options.AppOptions.set("disableStream", hashParams.disablestream === "true");
  189. }
  190. if ("disableautofetch" in hashParams) {
  191. _app_options.AppOptions.set("disableAutoFetch", hashParams.disableautofetch === "true");
  192. }
  193. if ("disablefontface" in hashParams) {
  194. _app_options.AppOptions.set("disableFontFace", hashParams.disablefontface === "true");
  195. }
  196. if ("disablehistory" in hashParams) {
  197. _app_options.AppOptions.set("disableHistory", hashParams.disablehistory === "true");
  198. }
  199. if ("webgl" in hashParams) {
  200. _app_options.AppOptions.set("enableWebGL", hashParams.webgl === "true");
  201. }
  202. if ("verbosity" in hashParams) {
  203. _app_options.AppOptions.set("verbosity", hashParams.verbosity | 0);
  204. }
  205. if ("textlayer" in hashParams) {
  206. switch (hashParams.textlayer) {
  207. case "off":
  208. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  209. break;
  210. case "visible":
  211. case "shadow":
  212. case "hover":
  213. const viewer = this.appConfig.viewerContainer;
  214. viewer.classList.add("textLayer-" + hashParams.textlayer);
  215. break;
  216. }
  217. }
  218. if ("pdfbug" in hashParams) {
  219. _app_options.AppOptions.set("pdfBug", true);
  220. _app_options.AppOptions.set("fontExtraProperties", true);
  221. const enabled = hashParams.pdfbug.split(",");
  222. waitOn.push(loadAndEnablePDFBug(enabled));
  223. }
  224. if ("locale" in hashParams) {
  225. _app_options.AppOptions.set("locale", hashParams.locale);
  226. }
  227. return Promise.all(waitOn).catch(reason => {
  228. console.error(`_parseHashParameters: "${reason.message}".`);
  229. });
  230. },
  231. async _initializeL10n() {
  232. this.l10n = this.externalServices.createL10n({
  233. locale: _app_options.AppOptions.get("locale")
  234. });
  235. const dir = await this.l10n.getDirection();
  236. document.getElementsByTagName("html")[0].dir = dir;
  237. },
  238. async _initializeViewerComponents() {
  239. const appConfig = this.appConfig;
  240. const eventBus = appConfig.eventBus || new _ui_utils.EventBus({
  241. isInAutomation: this.externalServices.isInAutomation
  242. });
  243. this.eventBus = eventBus;
  244. this.overlayManager = new _overlay_manager.OverlayManager();
  245. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  246. pdfRenderingQueue.onIdle = this.cleanup.bind(this);
  247. this.pdfRenderingQueue = pdfRenderingQueue;
  248. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  249. eventBus,
  250. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  251. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  252. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  253. });
  254. this.pdfLinkService = pdfLinkService;
  255. const downloadManager = this.externalServices.createDownloadManager();
  256. this.downloadManager = downloadManager;
  257. const findController = new _pdf_find_controller.PDFFindController({
  258. linkService: pdfLinkService,
  259. eventBus
  260. });
  261. this.findController = findController;
  262. const container = appConfig.mainContainer;
  263. const viewer = appConfig.viewerContainer;
  264. this.pdfViewer = new _pdf_viewer.PDFViewer({
  265. container,
  266. viewer,
  267. eventBus,
  268. renderingQueue: pdfRenderingQueue,
  269. linkService: pdfLinkService,
  270. downloadManager,
  271. findController,
  272. renderer: _app_options.AppOptions.get("renderer"),
  273. enableWebGL: _app_options.AppOptions.get("enableWebGL"),
  274. l10n: this.l10n,
  275. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  276. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  277. renderInteractiveForms: _app_options.AppOptions.get("renderInteractiveForms"),
  278. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  279. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  280. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels")
  281. });
  282. pdfRenderingQueue.setViewer(this.pdfViewer);
  283. pdfLinkService.setViewer(this.pdfViewer);
  284. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  285. container: appConfig.sidebar.thumbnailView,
  286. eventBus,
  287. renderingQueue: pdfRenderingQueue,
  288. linkService: pdfLinkService,
  289. l10n: this.l10n
  290. });
  291. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  292. this.pdfHistory = new _pdf_history.PDFHistory({
  293. linkService: pdfLinkService,
  294. eventBus
  295. });
  296. pdfLinkService.setHistory(this.pdfHistory);
  297. if (!this.supportsIntegratedFind) {
  298. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  299. }
  300. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
  301. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  302. container,
  303. eventBus,
  304. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  305. });
  306. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  307. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  308. if (this.supportsFullscreen) {
  309. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  310. container,
  311. pdfViewer: this.pdfViewer,
  312. eventBus,
  313. contextMenuItems: appConfig.fullscreen
  314. });
  315. }
  316. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n);
  317. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  318. container: appConfig.sidebar.outlineView,
  319. eventBus,
  320. linkService: pdfLinkService
  321. });
  322. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  323. container: appConfig.sidebar.attachmentsView,
  324. eventBus,
  325. downloadManager
  326. });
  327. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  328. container: appConfig.sidebar.layersView,
  329. eventBus,
  330. l10n: this.l10n
  331. });
  332. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  333. elements: appConfig.sidebar,
  334. pdfViewer: this.pdfViewer,
  335. pdfThumbnailViewer: this.pdfThumbnailViewer,
  336. eventBus,
  337. l10n: this.l10n
  338. });
  339. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  340. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  341. },
  342. run(config) {
  343. this.initialize(config).then(webViewerInitialized);
  344. },
  345. get initialized() {
  346. return this._initializedCapability.settled;
  347. },
  348. get initializedPromise() {
  349. return this._initializedCapability.promise;
  350. },
  351. zoomIn(ticks) {
  352. if (this.pdfViewer.isInPresentationMode) {
  353. return;
  354. }
  355. let newScale = this.pdfViewer.currentScale;
  356. do {
  357. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  358. newScale = Math.ceil(newScale * 10) / 10;
  359. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  360. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  361. this.pdfViewer.currentScaleValue = newScale;
  362. },
  363. zoomOut(ticks) {
  364. if (this.pdfViewer.isInPresentationMode) {
  365. return;
  366. }
  367. let newScale = this.pdfViewer.currentScale;
  368. do {
  369. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  370. newScale = Math.floor(newScale * 10) / 10;
  371. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  372. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  373. this.pdfViewer.currentScaleValue = newScale;
  374. },
  375. zoomReset() {
  376. if (this.pdfViewer.isInPresentationMode) {
  377. return;
  378. }
  379. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  380. },
  381. get pagesCount() {
  382. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  383. },
  384. get page() {
  385. return this.pdfViewer.currentPageNumber;
  386. },
  387. set page(val) {
  388. this.pdfViewer.currentPageNumber = val;
  389. },
  390. get printing() {
  391. return !!this.printService;
  392. },
  393. get supportsPrinting() {
  394. return PDFPrintServiceFactory.instance.supportsPrinting;
  395. },
  396. get supportsFullscreen() {
  397. let support;
  398. const doc = document.documentElement;
  399. support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
  400. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
  401. support = false;
  402. }
  403. return (0, _pdf.shadow)(this, "supportsFullscreen", support);
  404. },
  405. get supportsIntegratedFind() {
  406. return this.externalServices.supportsIntegratedFind;
  407. },
  408. get supportsDocumentFonts() {
  409. return this.externalServices.supportsDocumentFonts;
  410. },
  411. get loadingBar() {
  412. const bar = new _ui_utils.ProgressBar("#loadingBar");
  413. return (0, _pdf.shadow)(this, "loadingBar", bar);
  414. },
  415. get supportedMouseWheelZoomModifierKeys() {
  416. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  417. },
  418. initPassiveLoading() {
  419. throw new Error("Not implemented: initPassiveLoading");
  420. },
  421. setTitleUsingUrl(url = "") {
  422. this.url = url;
  423. this.baseUrl = url.split("#")[0];
  424. let title = (0, _ui_utils.getPDFFileNameFromURL)(url, "");
  425. if (!title) {
  426. try {
  427. title = decodeURIComponent((0, _pdf.getFilenameFromUrl)(url)) || url;
  428. } catch (ex) {
  429. title = url;
  430. }
  431. }
  432. this.setTitle(title);
  433. },
  434. setTitle(title) {
  435. if (this.isViewerEmbedded) {
  436. return;
  437. }
  438. document.title = title;
  439. },
  440. async close() {
  441. const errorWrapper = this.appConfig.errorWrapper.container;
  442. errorWrapper.setAttribute("hidden", "true");
  443. if (!this.pdfLoadingTask) {
  444. return undefined;
  445. }
  446. const promise = this.pdfLoadingTask.destroy();
  447. this.pdfLoadingTask = null;
  448. if (this.pdfDocument) {
  449. this.pdfDocument = null;
  450. this.pdfThumbnailViewer.setDocument(null);
  451. this.pdfViewer.setDocument(null);
  452. this.pdfLinkService.setDocument(null);
  453. this.pdfDocumentProperties.setDocument(null);
  454. }
  455. webViewerResetPermissions();
  456. this.store = null;
  457. this.isInitialViewSet = false;
  458. this.downloadComplete = false;
  459. this.url = "";
  460. this.baseUrl = "";
  461. this.contentDispositionFilename = null;
  462. this.triggerDelayedFallback = null;
  463. this._saveInProgress = false;
  464. this.pdfSidebar.reset();
  465. this.pdfOutlineViewer.reset();
  466. this.pdfAttachmentViewer.reset();
  467. this.pdfLayerViewer.reset();
  468. if (this.pdfHistory) {
  469. this.pdfHistory.reset();
  470. }
  471. if (this.findBar) {
  472. this.findBar.reset();
  473. }
  474. this.toolbar.reset();
  475. this.secondaryToolbar.reset();
  476. if (typeof PDFBug !== "undefined") {
  477. PDFBug.cleanup();
  478. }
  479. return promise;
  480. },
  481. async open(file, args) {
  482. if (this.pdfLoadingTask) {
  483. await this.close();
  484. }
  485. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  486. for (const key in workerParameters) {
  487. _pdf.GlobalWorkerOptions[key] = workerParameters[key];
  488. }
  489. const parameters = Object.create(null);
  490. if (typeof file === "string") {
  491. this.setTitleUsingUrl(file);
  492. parameters.url = file;
  493. } else if (file && "byteLength" in file) {
  494. parameters.data = file;
  495. } else if (file.url && file.originalUrl) {
  496. this.setTitleUsingUrl(file.originalUrl);
  497. parameters.url = file.url;
  498. }
  499. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  500. for (const key in apiParameters) {
  501. let value = apiParameters[key];
  502. if (key === "docBaseUrl" && !value) {}
  503. parameters[key] = value;
  504. }
  505. if (args) {
  506. for (const key in args) {
  507. const value = args[key];
  508. if (key === "length") {
  509. this.pdfDocumentProperties.setFileSize(value);
  510. }
  511. parameters[key] = value;
  512. }
  513. }
  514. const loadingTask = (0, _pdf.getDocument)(parameters);
  515. this.pdfLoadingTask = loadingTask;
  516. loadingTask.onPassword = (updateCallback, reason) => {
  517. this.pdfLinkService.externalLinkEnabled = false;
  518. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  519. this.passwordPrompt.open();
  520. };
  521. loadingTask.onProgress = ({
  522. loaded,
  523. total
  524. }) => {
  525. this.progress(loaded / total);
  526. };
  527. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  528. return loadingTask.promise.then(pdfDocument => {
  529. this.load(pdfDocument);
  530. }, exception => {
  531. if (loadingTask !== this.pdfLoadingTask) {
  532. return undefined;
  533. }
  534. const message = exception && exception.message;
  535. let loadingErrorMessage;
  536. if (exception instanceof _pdf.InvalidPDFException) {
  537. loadingErrorMessage = this.l10n.get("invalid_file_error", null, "Invalid or corrupted PDF file.");
  538. } else if (exception instanceof _pdf.MissingPDFException) {
  539. loadingErrorMessage = this.l10n.get("missing_file_error", null, "Missing PDF file.");
  540. } else if (exception instanceof _pdf.UnexpectedResponseException) {
  541. loadingErrorMessage = this.l10n.get("unexpected_response_error", null, "Unexpected server response.");
  542. } else {
  543. loadingErrorMessage = this.l10n.get("loading_error", null, "An error occurred while loading the PDF.");
  544. }
  545. return loadingErrorMessage.then(msg => {
  546. this.error(msg, {
  547. message
  548. });
  549. throw exception;
  550. });
  551. });
  552. },
  553. download({
  554. sourceEventType = "download"
  555. } = {}) {
  556. function downloadByUrl() {
  557. downloadManager.downloadUrl(url, filename);
  558. }
  559. const url = this.baseUrl;
  560. const filename = this.contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url);
  561. const downloadManager = this.downloadManager;
  562. downloadManager.onerror = err => {
  563. this.error(`PDF failed to download: ${err}`);
  564. };
  565. if (!this.pdfDocument || !this.downloadComplete) {
  566. downloadByUrl();
  567. return;
  568. }
  569. this.pdfDocument.getData().then(function (data) {
  570. const blob = new Blob([data], {
  571. type: "application/pdf"
  572. });
  573. downloadManager.download(blob, url, filename, sourceEventType);
  574. }).catch(downloadByUrl);
  575. },
  576. save({
  577. sourceEventType = "download"
  578. } = {}) {
  579. if (this._saveInProgress) {
  580. return;
  581. }
  582. const url = this.baseUrl;
  583. const filename = this.contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url);
  584. const downloadManager = this.downloadManager;
  585. downloadManager.onerror = err => {
  586. this.error(`PDF failed to be saved: ${err}`);
  587. };
  588. if (!this.pdfDocument || !this.downloadComplete) {
  589. this.download({
  590. sourceEventType
  591. });
  592. return;
  593. }
  594. this._saveInProgress = true;
  595. this.pdfDocument.saveDocument(this.pdfDocument.annotationStorage).then(data => {
  596. const blob = new Blob([data], {
  597. type: "application/pdf"
  598. });
  599. downloadManager.download(blob, url, filename, sourceEventType);
  600. }).catch(() => {
  601. this.download({
  602. sourceEventType
  603. });
  604. }).finally(() => {
  605. this._saveInProgress = false;
  606. });
  607. },
  608. _delayedFallback(featureId) {
  609. this.externalServices.reportTelemetry({
  610. type: "unsupportedFeature",
  611. featureId
  612. });
  613. if (!this.triggerDelayedFallback) {
  614. this.triggerDelayedFallback = () => {
  615. this.fallback(featureId);
  616. this.triggerDelayedFallback = null;
  617. };
  618. }
  619. },
  620. fallback(featureId) {
  621. this.externalServices.reportTelemetry({
  622. type: "unsupportedFeature",
  623. featureId
  624. });
  625. if (this.fellback) {
  626. return;
  627. }
  628. this.fellback = true;
  629. this.externalServices.fallback({
  630. featureId,
  631. url: this.baseUrl
  632. }, function response(download) {
  633. if (!download) {
  634. return;
  635. }
  636. PDFViewerApplication.download({
  637. sourceEventType: "download"
  638. });
  639. });
  640. },
  641. error(message, moreInfo) {
  642. const moreInfoText = [this.l10n.get("error_version_info", {
  643. version: _pdf.version || "?",
  644. build: _pdf.build || "?"
  645. }, "PDF.js v{{version}} (build: {{build}})")];
  646. if (moreInfo) {
  647. moreInfoText.push(this.l10n.get("error_message", {
  648. message: moreInfo.message
  649. }, "Message: {{message}}"));
  650. if (moreInfo.stack) {
  651. moreInfoText.push(this.l10n.get("error_stack", {
  652. stack: moreInfo.stack
  653. }, "Stack: {{stack}}"));
  654. } else {
  655. if (moreInfo.filename) {
  656. moreInfoText.push(this.l10n.get("error_file", {
  657. file: moreInfo.filename
  658. }, "File: {{file}}"));
  659. }
  660. if (moreInfo.lineNumber) {
  661. moreInfoText.push(this.l10n.get("error_line", {
  662. line: moreInfo.lineNumber
  663. }, "Line: {{line}}"));
  664. }
  665. }
  666. }
  667. const errorWrapperConfig = this.appConfig.errorWrapper;
  668. const errorWrapper = errorWrapperConfig.container;
  669. errorWrapper.removeAttribute("hidden");
  670. const errorMessage = errorWrapperConfig.errorMessage;
  671. errorMessage.textContent = message;
  672. const closeButton = errorWrapperConfig.closeButton;
  673. closeButton.onclick = function () {
  674. errorWrapper.setAttribute("hidden", "true");
  675. };
  676. const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  677. const moreInfoButton = errorWrapperConfig.moreInfoButton;
  678. const lessInfoButton = errorWrapperConfig.lessInfoButton;
  679. moreInfoButton.onclick = function () {
  680. errorMoreInfo.removeAttribute("hidden");
  681. moreInfoButton.setAttribute("hidden", "true");
  682. lessInfoButton.removeAttribute("hidden");
  683. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  684. };
  685. lessInfoButton.onclick = function () {
  686. errorMoreInfo.setAttribute("hidden", "true");
  687. moreInfoButton.removeAttribute("hidden");
  688. lessInfoButton.setAttribute("hidden", "true");
  689. };
  690. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  691. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  692. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  693. moreInfoButton.removeAttribute("hidden");
  694. lessInfoButton.setAttribute("hidden", "true");
  695. Promise.all(moreInfoText).then(parts => {
  696. errorMoreInfo.value = parts.join("\n");
  697. });
  698. },
  699. progress(level) {
  700. if (this.downloadComplete) {
  701. return;
  702. }
  703. const percent = Math.round(level * 100);
  704. if (percent > this.loadingBar.percent || isNaN(percent)) {
  705. this.loadingBar.percent = percent;
  706. const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams.disableAutoFetch : _app_options.AppOptions.get("disableAutoFetch");
  707. if (disableAutoFetch && percent) {
  708. if (this.disableAutoFetchLoadingBarTimeout) {
  709. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  710. this.disableAutoFetchLoadingBarTimeout = null;
  711. }
  712. this.loadingBar.show();
  713. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  714. this.loadingBar.hide();
  715. this.disableAutoFetchLoadingBarTimeout = null;
  716. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  717. }
  718. }
  719. },
  720. load(pdfDocument) {
  721. this.pdfDocument = pdfDocument;
  722. pdfDocument.getDownloadInfo().then(() => {
  723. this.downloadComplete = true;
  724. this.loadingBar.hide();
  725. firstPagePromise.then(() => {
  726. this.eventBus.dispatch("documentloaded", {
  727. source: this
  728. });
  729. });
  730. });
  731. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  732. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  733. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  734. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  735. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  736. let baseDocumentUrl;
  737. baseDocumentUrl = null;
  738. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  739. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  740. const annotationStorage = pdfDocument.annotationStorage;
  741. annotationStorage.onSetModified = function () {
  742. window.addEventListener("beforeunload", beforeUnload);
  743. };
  744. annotationStorage.onResetModified = function () {
  745. window.removeEventListener("beforeunload", beforeUnload);
  746. };
  747. const pdfViewer = this.pdfViewer;
  748. pdfViewer.setDocument(pdfDocument);
  749. const {
  750. firstPagePromise,
  751. onePageRendered,
  752. pagesPromise
  753. } = pdfViewer;
  754. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  755. pdfThumbnailViewer.setDocument(pdfDocument);
  756. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprint)).getMultiple({
  757. page: null,
  758. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  759. scrollLeft: "0",
  760. scrollTop: "0",
  761. rotation: null,
  762. sidebarView: _pdf_sidebar.SidebarView.UNKNOWN,
  763. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  764. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  765. }).catch(() => {
  766. return Object.create(null);
  767. });
  768. firstPagePromise.then(pdfPage => {
  769. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  770. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  771. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  772. this._initializePdfHistory({
  773. fingerprint: pdfDocument.fingerprint,
  774. viewOnLoad,
  775. initialDest: openAction && openAction.dest
  776. });
  777. const initialBookmark = this.initialBookmark;
  778. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  779. let hash = zoom ? `zoom=${zoom}` : null;
  780. let rotation = null;
  781. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  782. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  783. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  784. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  785. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  786. rotation = parseInt(stored.rotation, 10);
  787. if (sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) {
  788. sidebarView = stored.sidebarView | 0;
  789. }
  790. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  791. scrollMode = stored.scrollMode | 0;
  792. }
  793. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  794. spreadMode = stored.spreadMode | 0;
  795. }
  796. }
  797. if (pageMode && sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) {
  798. sidebarView = apiPageModeToSidebarView(pageMode);
  799. }
  800. if (pageLayout && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  801. spreadMode = apiPageLayoutToSpreadMode(pageLayout);
  802. }
  803. this.setInitialView(hash, {
  804. rotation,
  805. sidebarView,
  806. scrollMode,
  807. spreadMode
  808. });
  809. this.eventBus.dispatch("documentinit", {
  810. source: this
  811. });
  812. if (!this.isViewerEmbedded) {
  813. pdfViewer.focus();
  814. }
  815. this._initializePermissions(pdfDocument);
  816. await Promise.race([pagesPromise, new Promise(resolve => {
  817. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  818. })]);
  819. if (!initialBookmark && !hash) {
  820. return;
  821. }
  822. if (pdfViewer.hasEqualPageSizes) {
  823. return;
  824. }
  825. this.initialBookmark = initialBookmark;
  826. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  827. this.setInitialView(hash);
  828. }).catch(() => {
  829. this.setInitialView();
  830. }).then(function () {
  831. pdfViewer.update();
  832. });
  833. });
  834. pagesPromise.then(() => {
  835. this._initializeAutoPrint(pdfDocument, openActionPromise);
  836. });
  837. onePageRendered.then(() => {
  838. pdfDocument.getOutline().then(outline => {
  839. this.pdfOutlineViewer.render({
  840. outline
  841. });
  842. });
  843. pdfDocument.getAttachments().then(attachments => {
  844. this.pdfAttachmentViewer.render({
  845. attachments
  846. });
  847. });
  848. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  849. this.pdfLayerViewer.render({
  850. optionalContentConfig,
  851. pdfDocument
  852. });
  853. });
  854. });
  855. this._initializePageLabels(pdfDocument);
  856. this._initializeMetadata(pdfDocument);
  857. },
  858. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  859. const [openAction, javaScript] = await Promise.all([openActionPromise, pdfDocument.getJavaScript()]);
  860. if (pdfDocument !== this.pdfDocument) {
  861. return;
  862. }
  863. let triggerAutoPrint = false;
  864. if (openAction && openAction.action === "Print") {
  865. triggerAutoPrint = true;
  866. }
  867. if (javaScript) {
  868. javaScript.some(js => {
  869. if (!js) {
  870. return false;
  871. }
  872. console.warn("Warning: JavaScript is not supported");
  873. this._delayedFallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
  874. return true;
  875. });
  876. if (!triggerAutoPrint) {
  877. for (const js of javaScript) {
  878. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  879. triggerAutoPrint = true;
  880. break;
  881. }
  882. }
  883. }
  884. }
  885. if (!this.supportsPrinting) {
  886. return;
  887. }
  888. if (triggerAutoPrint) {
  889. setTimeout(function () {
  890. window.print();
  891. });
  892. }
  893. },
  894. async _initializeMetadata(pdfDocument) {
  895. const {
  896. info,
  897. metadata,
  898. contentDispositionFilename
  899. } = await pdfDocument.getMetadata();
  900. if (pdfDocument !== this.pdfDocument) {
  901. return;
  902. }
  903. this.documentInfo = info;
  904. this.metadata = metadata;
  905. this.contentDispositionFilename = contentDispositionFilename;
  906. console.log(`PDF ${pdfDocument.fingerprint} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdf.version || "-"}` + `${this.pdfViewer.enableWebGL ? " [WebGL]" : ""})`);
  907. let pdfTitle;
  908. const infoTitle = info && info.Title;
  909. if (infoTitle) {
  910. pdfTitle = infoTitle;
  911. }
  912. const metadataTitle = metadata && metadata.get("dc:title");
  913. if (metadataTitle) {
  914. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  915. pdfTitle = metadataTitle;
  916. }
  917. }
  918. if (pdfTitle) {
  919. this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
  920. } else if (contentDispositionFilename) {
  921. this.setTitle(contentDispositionFilename);
  922. }
  923. if (info.IsXFAPresent && !info.IsAcroFormPresent) {
  924. console.warn("Warning: XFA is not supported");
  925. this._delayedFallback(_pdf.UNSUPPORTED_FEATURES.forms);
  926. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderInteractiveForms) {
  927. console.warn("Warning: Interactive form support is not enabled");
  928. this._delayedFallback(_pdf.UNSUPPORTED_FEATURES.forms);
  929. }
  930. let versionId = "other";
  931. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  932. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  933. }
  934. let generatorId = "other";
  935. if (info.Producer) {
  936. const producer = info.Producer.toLowerCase();
  937. KNOWN_GENERATORS.some(function (generator) {
  938. if (!producer.includes(generator)) {
  939. return false;
  940. }
  941. generatorId = generator.replace(/[ .\-]/g, "_");
  942. return true;
  943. });
  944. }
  945. let formType = null;
  946. if (info.IsXFAPresent) {
  947. formType = "xfa";
  948. } else if (info.IsAcroFormPresent) {
  949. formType = "acroform";
  950. }
  951. this.externalServices.reportTelemetry({
  952. type: "documentInfo",
  953. version: versionId,
  954. generator: generatorId,
  955. formType
  956. });
  957. },
  958. async _initializePageLabels(pdfDocument) {
  959. const labels = await pdfDocument.getPageLabels();
  960. if (pdfDocument !== this.pdfDocument) {
  961. return;
  962. }
  963. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  964. return;
  965. }
  966. const numLabels = labels.length;
  967. if (numLabels !== this.pagesCount) {
  968. console.error("The number of Page Labels does not match the number of pages in the document.");
  969. return;
  970. }
  971. let i = 0;
  972. while (i < numLabels && labels[i] === (i + 1).toString()) {
  973. i++;
  974. }
  975. if (i === numLabels) {
  976. return;
  977. }
  978. const {
  979. pdfViewer,
  980. pdfThumbnailViewer,
  981. toolbar
  982. } = this;
  983. pdfViewer.setPageLabels(labels);
  984. pdfThumbnailViewer.setPageLabels(labels);
  985. toolbar.setPagesCount(numLabels, true);
  986. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  987. },
  988. _initializePdfHistory({
  989. fingerprint,
  990. viewOnLoad,
  991. initialDest = null
  992. }) {
  993. if (this.isViewerEmbedded || _app_options.AppOptions.get("disableHistory")) {
  994. return;
  995. }
  996. this.pdfHistory.initialize({
  997. fingerprint,
  998. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  999. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1000. });
  1001. if (this.pdfHistory.initialBookmark) {
  1002. this.initialBookmark = this.pdfHistory.initialBookmark;
  1003. this.initialRotation = this.pdfHistory.initialRotation;
  1004. }
  1005. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1006. this.initialBookmark = JSON.stringify(initialDest);
  1007. this.pdfHistory.push({
  1008. explicitDest: initialDest,
  1009. pageNumber: null
  1010. });
  1011. }
  1012. },
  1013. async _initializePermissions(pdfDocument) {
  1014. const permissions = await pdfDocument.getPermissions();
  1015. if (pdfDocument !== this.pdfDocument) {
  1016. return;
  1017. }
  1018. if (!permissions || !_app_options.AppOptions.get("enablePermissions")) {
  1019. return;
  1020. }
  1021. if (!permissions.includes(_pdf.PermissionFlag.COPY)) {
  1022. this.appConfig.viewerContainer.classList.add(ENABLE_PERMISSIONS_CLASS);
  1023. }
  1024. },
  1025. setInitialView(storedHash, {
  1026. rotation,
  1027. sidebarView,
  1028. scrollMode,
  1029. spreadMode
  1030. } = {}) {
  1031. const setRotation = angle => {
  1032. if ((0, _ui_utils.isValidRotation)(angle)) {
  1033. this.pdfViewer.pagesRotation = angle;
  1034. }
  1035. };
  1036. const setViewerModes = (scroll, spread) => {
  1037. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1038. this.pdfViewer.scrollMode = scroll;
  1039. }
  1040. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1041. this.pdfViewer.spreadMode = spread;
  1042. }
  1043. };
  1044. this.isInitialViewSet = true;
  1045. this.pdfSidebar.setInitialView(sidebarView);
  1046. setViewerModes(scrollMode, spreadMode);
  1047. if (this.initialBookmark) {
  1048. setRotation(this.initialRotation);
  1049. delete this.initialRotation;
  1050. this.pdfLinkService.setHash(this.initialBookmark);
  1051. this.initialBookmark = null;
  1052. } else if (storedHash) {
  1053. setRotation(rotation);
  1054. this.pdfLinkService.setHash(storedHash);
  1055. }
  1056. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1057. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1058. if (!this.pdfViewer.currentScaleValue) {
  1059. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1060. }
  1061. },
  1062. cleanup() {
  1063. if (!this.pdfDocument) {
  1064. return;
  1065. }
  1066. this.pdfViewer.cleanup();
  1067. this.pdfThumbnailViewer.cleanup();
  1068. if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
  1069. this.pdfDocument.cleanup();
  1070. }
  1071. },
  1072. forceRendering() {
  1073. this.pdfRenderingQueue.printing = this.printing;
  1074. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1075. this.pdfRenderingQueue.renderHighestPriority();
  1076. },
  1077. beforePrint() {
  1078. if (this.printService) {
  1079. return;
  1080. }
  1081. if (!this.supportsPrinting) {
  1082. this.l10n.get("printing_not_supported", null, "Warning: Printing is not fully supported by this browser.").then(printMessage => {
  1083. this.error(printMessage);
  1084. });
  1085. return;
  1086. }
  1087. if (!this.pdfViewer.pageViewsReady) {
  1088. this.l10n.get("printing_not_ready", null, "Warning: The PDF is not fully loaded for printing.").then(notReadyMessage => {
  1089. window.alert(notReadyMessage);
  1090. });
  1091. return;
  1092. }
  1093. const pagesOverview = this.pdfViewer.getPagesOverview();
  1094. const printContainer = this.appConfig.printContainer;
  1095. const printResolution = _app_options.AppOptions.get("printResolution");
  1096. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1097. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this.l10n);
  1098. this.printService = printService;
  1099. this.forceRendering();
  1100. printService.layout();
  1101. this.externalServices.reportTelemetry({
  1102. type: "print"
  1103. });
  1104. },
  1105. afterPrint() {
  1106. if (this.printService) {
  1107. this.printService.destroy();
  1108. this.printService = null;
  1109. if (this.pdfDocument) {
  1110. this.pdfDocument.annotationStorage.resetModified();
  1111. }
  1112. }
  1113. this.forceRendering();
  1114. },
  1115. rotatePages(delta) {
  1116. if (!this.pdfDocument) {
  1117. return;
  1118. }
  1119. const newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
  1120. this.pdfViewer.pagesRotation = newRotation;
  1121. },
  1122. requestPresentationMode() {
  1123. if (!this.pdfPresentationMode) {
  1124. return;
  1125. }
  1126. this.pdfPresentationMode.request();
  1127. },
  1128. bindEvents() {
  1129. const {
  1130. eventBus,
  1131. _boundEvents
  1132. } = this;
  1133. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1134. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1135. eventBus._on("resize", webViewerResize);
  1136. eventBus._on("hashchange", webViewerHashchange);
  1137. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1138. eventBus._on("afterprint", _boundEvents.afterPrint);
  1139. eventBus._on("pagerendered", webViewerPageRendered);
  1140. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1141. eventBus._on("pagechanging", webViewerPageChanging);
  1142. eventBus._on("scalechanging", webViewerScaleChanging);
  1143. eventBus._on("rotationchanging", webViewerRotationChanging);
  1144. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1145. eventBus._on("pagemode", webViewerPageMode);
  1146. eventBus._on("namedaction", webViewerNamedAction);
  1147. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1148. eventBus._on("presentationmode", webViewerPresentationMode);
  1149. eventBus._on("print", webViewerPrint);
  1150. eventBus._on("download", webViewerDownload);
  1151. eventBus._on("save", webViewerSave);
  1152. eventBus._on("firstpage", webViewerFirstPage);
  1153. eventBus._on("lastpage", webViewerLastPage);
  1154. eventBus._on("nextpage", webViewerNextPage);
  1155. eventBus._on("previouspage", webViewerPreviousPage);
  1156. eventBus._on("zoomin", webViewerZoomIn);
  1157. eventBus._on("zoomout", webViewerZoomOut);
  1158. eventBus._on("zoomreset", webViewerZoomReset);
  1159. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1160. eventBus._on("scalechanged", webViewerScaleChanged);
  1161. eventBus._on("rotatecw", webViewerRotateCw);
  1162. eventBus._on("rotateccw", webViewerRotateCcw);
  1163. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1164. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1165. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1166. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1167. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1168. eventBus._on("documentproperties", webViewerDocumentProperties);
  1169. eventBus._on("find", webViewerFind);
  1170. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1171. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1172. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1173. eventBus._on("fileinputchange", webViewerFileInputChange);
  1174. eventBus._on("openfile", webViewerOpenFile);
  1175. },
  1176. bindWindowEvents() {
  1177. const {
  1178. eventBus,
  1179. _boundEvents
  1180. } = this;
  1181. _boundEvents.windowResize = () => {
  1182. eventBus.dispatch("resize", {
  1183. source: window
  1184. });
  1185. };
  1186. _boundEvents.windowHashChange = () => {
  1187. eventBus.dispatch("hashchange", {
  1188. source: window,
  1189. hash: document.location.hash.substring(1)
  1190. });
  1191. };
  1192. _boundEvents.windowBeforePrint = () => {
  1193. eventBus.dispatch("beforeprint", {
  1194. source: window
  1195. });
  1196. };
  1197. _boundEvents.windowAfterPrint = () => {
  1198. eventBus.dispatch("afterprint", {
  1199. source: window
  1200. });
  1201. };
  1202. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1203. window.addEventListener("wheel", webViewerWheel, {
  1204. passive: false
  1205. });
  1206. window.addEventListener("touchstart", webViewerTouchStart, {
  1207. passive: false
  1208. });
  1209. window.addEventListener("click", webViewerClick);
  1210. window.addEventListener("keydown", webViewerKeyDown);
  1211. window.addEventListener("keyup", webViewerKeyUp);
  1212. window.addEventListener("resize", _boundEvents.windowResize);
  1213. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1214. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1215. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1216. },
  1217. unbindEvents() {
  1218. const {
  1219. eventBus,
  1220. _boundEvents
  1221. } = this;
  1222. eventBus._off("resize", webViewerResize);
  1223. eventBus._off("hashchange", webViewerHashchange);
  1224. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1225. eventBus._off("afterprint", _boundEvents.afterPrint);
  1226. eventBus._off("pagerendered", webViewerPageRendered);
  1227. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1228. eventBus._off("pagechanging", webViewerPageChanging);
  1229. eventBus._off("scalechanging", webViewerScaleChanging);
  1230. eventBus._off("rotationchanging", webViewerRotationChanging);
  1231. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1232. eventBus._off("pagemode", webViewerPageMode);
  1233. eventBus._off("namedaction", webViewerNamedAction);
  1234. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1235. eventBus._off("presentationmode", webViewerPresentationMode);
  1236. eventBus._off("print", webViewerPrint);
  1237. eventBus._off("download", webViewerDownload);
  1238. eventBus._off("save", webViewerSave);
  1239. eventBus._off("firstpage", webViewerFirstPage);
  1240. eventBus._off("lastpage", webViewerLastPage);
  1241. eventBus._off("nextpage", webViewerNextPage);
  1242. eventBus._off("previouspage", webViewerPreviousPage);
  1243. eventBus._off("zoomin", webViewerZoomIn);
  1244. eventBus._off("zoomout", webViewerZoomOut);
  1245. eventBus._off("zoomreset", webViewerZoomReset);
  1246. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1247. eventBus._off("scalechanged", webViewerScaleChanged);
  1248. eventBus._off("rotatecw", webViewerRotateCw);
  1249. eventBus._off("rotateccw", webViewerRotateCcw);
  1250. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1251. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1252. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1253. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1254. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1255. eventBus._off("documentproperties", webViewerDocumentProperties);
  1256. eventBus._off("find", webViewerFind);
  1257. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1258. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1259. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1260. eventBus._off("fileinputchange", webViewerFileInputChange);
  1261. eventBus._off("openfile", webViewerOpenFile);
  1262. _boundEvents.beforePrint = null;
  1263. _boundEvents.afterPrint = null;
  1264. },
  1265. unbindWindowEvents() {
  1266. const {
  1267. _boundEvents
  1268. } = this;
  1269. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1270. window.removeEventListener("wheel", webViewerWheel, {
  1271. passive: false
  1272. });
  1273. window.removeEventListener("touchstart", webViewerTouchStart, {
  1274. passive: false
  1275. });
  1276. window.removeEventListener("click", webViewerClick);
  1277. window.removeEventListener("keydown", webViewerKeyDown);
  1278. window.removeEventListener("keyup", webViewerKeyUp);
  1279. window.removeEventListener("resize", _boundEvents.windowResize);
  1280. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1281. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1282. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1283. _boundEvents.windowResize = null;
  1284. _boundEvents.windowHashChange = null;
  1285. _boundEvents.windowBeforePrint = null;
  1286. _boundEvents.windowAfterPrint = null;
  1287. },
  1288. accumulateWheelTicks(ticks) {
  1289. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  1290. this._wheelUnusedTicks = 0;
  1291. }
  1292. this._wheelUnusedTicks += ticks;
  1293. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  1294. this._wheelUnusedTicks -= wholeTicks;
  1295. return wholeTicks;
  1296. }
  1297. };
  1298. exports.PDFViewerApplication = PDFViewerApplication;
  1299. let validateFileURL;
  1300. {
  1301. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1302. validateFileURL = function (file) {
  1303. if (file === undefined) {
  1304. return;
  1305. }
  1306. try {
  1307. const viewerOrigin = new URL(window.location.href).origin || "null";
  1308. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1309. return;
  1310. }
  1311. const {
  1312. origin,
  1313. protocol
  1314. } = new URL(file, window.location.href);
  1315. if (origin !== viewerOrigin && protocol !== "blob:") {
  1316. throw new Error("file origin does not match viewer's");
  1317. }
  1318. } catch (ex) {
  1319. const message = ex && ex.message;
  1320. PDFViewerApplication.l10n.get("loading_error", null, "An error occurred while loading the PDF.").then(loadingErrorMessage => {
  1321. PDFViewerApplication.error(loadingErrorMessage, {
  1322. message
  1323. });
  1324. });
  1325. throw ex;
  1326. }
  1327. };
  1328. }
  1329. async function loadFakeWorker() {
  1330. if (!_pdf.GlobalWorkerOptions.workerSrc) {
  1331. _pdf.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc");
  1332. }
  1333. return (0, _pdf.loadScript)(_pdf.PDFWorker.getWorkerSrc());
  1334. }
  1335. function loadAndEnablePDFBug(enabledTabs) {
  1336. const appConfig = PDFViewerApplication.appConfig;
  1337. return (0, _pdf.loadScript)(appConfig.debuggerScriptPath).then(function () {
  1338. PDFBug.enable(enabledTabs);
  1339. PDFBug.init({
  1340. OPS: _pdf.OPS
  1341. }, appConfig.mainContainer);
  1342. });
  1343. }
  1344. function webViewerInitialized() {
  1345. const appConfig = PDFViewerApplication.appConfig;
  1346. let file;
  1347. const queryString = document.location.search.substring(1);
  1348. const params = (0, _ui_utils.parseQueryString)(queryString);
  1349. file = "file" in params ? params.file : _app_options.AppOptions.get("defaultUrl");
  1350. validateFileURL(file);
  1351. const fileInput = document.createElement("input");
  1352. fileInput.id = appConfig.openFileInputName;
  1353. fileInput.className = "fileInput";
  1354. fileInput.setAttribute("type", "file");
  1355. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1356. document.body.appendChild(fileInput);
  1357. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1358. appConfig.toolbar.openFile.setAttribute("hidden", "true");
  1359. appConfig.secondaryToolbar.openFileButton.setAttribute("hidden", "true");
  1360. } else {
  1361. fileInput.value = null;
  1362. }
  1363. fileInput.addEventListener("change", function (evt) {
  1364. const files = evt.target.files;
  1365. if (!files || files.length === 0) {
  1366. return;
  1367. }
  1368. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1369. source: this,
  1370. fileInput: evt.target
  1371. });
  1372. });
  1373. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1374. evt.preventDefault();
  1375. evt.dataTransfer.dropEffect = "move";
  1376. });
  1377. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1378. evt.preventDefault();
  1379. const files = evt.dataTransfer.files;
  1380. if (!files || files.length === 0) {
  1381. return;
  1382. }
  1383. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1384. source: this,
  1385. fileInput: evt.dataTransfer
  1386. });
  1387. });
  1388. if (!PDFViewerApplication.supportsDocumentFonts) {
  1389. _app_options.AppOptions.set("disableFontFace", true);
  1390. PDFViewerApplication.l10n.get("web_fonts_disabled", null, "Web fonts are disabled: unable to use embedded PDF fonts.").then(msg => {
  1391. console.warn(msg);
  1392. });
  1393. }
  1394. if (!PDFViewerApplication.supportsPrinting) {
  1395. appConfig.toolbar.print.classList.add("hidden");
  1396. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  1397. }
  1398. if (!PDFViewerApplication.supportsFullscreen) {
  1399. appConfig.toolbar.presentationModeButton.classList.add("hidden");
  1400. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  1401. }
  1402. if (PDFViewerApplication.supportsIntegratedFind) {
  1403. appConfig.toolbar.viewFind.classList.add("hidden");
  1404. }
  1405. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  1406. if (evt.target === this) {
  1407. PDFViewerApplication.eventBus.dispatch("resize", {
  1408. source: this
  1409. });
  1410. }
  1411. }, true);
  1412. try {
  1413. webViewerOpenFileViaURL(file);
  1414. } catch (reason) {
  1415. PDFViewerApplication.l10n.get("loading_error", null, "An error occurred while loading the PDF.").then(msg => {
  1416. PDFViewerApplication.error(msg, reason);
  1417. });
  1418. }
  1419. }
  1420. let webViewerOpenFileViaURL;
  1421. {
  1422. webViewerOpenFileViaURL = function (file) {
  1423. if (file && file.lastIndexOf("file:", 0) === 0) {
  1424. PDFViewerApplication.setTitleUsingUrl(file);
  1425. const xhr = new XMLHttpRequest();
  1426. xhr.onload = function () {
  1427. PDFViewerApplication.open(new Uint8Array(xhr.response));
  1428. };
  1429. xhr.open("GET", file);
  1430. xhr.responseType = "arraybuffer";
  1431. xhr.send();
  1432. return;
  1433. }
  1434. if (file) {
  1435. PDFViewerApplication.open(file);
  1436. }
  1437. };
  1438. }
  1439. function webViewerResetPermissions() {
  1440. const {
  1441. appConfig
  1442. } = PDFViewerApplication;
  1443. if (!appConfig) {
  1444. return;
  1445. }
  1446. appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  1447. }
  1448. function webViewerPageRendered(evt) {
  1449. const pageNumber = evt.pageNumber;
  1450. const pageIndex = pageNumber - 1;
  1451. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
  1452. if (pageNumber === PDFViewerApplication.page) {
  1453. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1454. }
  1455. if (!pageView) {
  1456. return;
  1457. }
  1458. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1459. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
  1460. thumbnailView.setImage(pageView);
  1461. }
  1462. if (typeof Stats !== "undefined" && Stats.enabled && pageView.stats) {
  1463. Stats.add(pageNumber, pageView.stats);
  1464. }
  1465. if (pageView.error) {
  1466. PDFViewerApplication.l10n.get("rendering_error", null, "An error occurred while rendering the page.").then(msg => {
  1467. PDFViewerApplication.error(msg, pageView.error);
  1468. });
  1469. }
  1470. PDFViewerApplication.externalServices.reportTelemetry({
  1471. type: "pageInfo",
  1472. timestamp: evt.timestamp
  1473. });
  1474. PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
  1475. PDFViewerApplication.externalServices.reportTelemetry({
  1476. type: "documentStats",
  1477. stats
  1478. });
  1479. });
  1480. }
  1481. function webViewerPageMode({
  1482. mode
  1483. }) {
  1484. let view;
  1485. switch (mode) {
  1486. case "thumbs":
  1487. view = _pdf_sidebar.SidebarView.THUMBS;
  1488. break;
  1489. case "bookmarks":
  1490. case "outline":
  1491. view = _pdf_sidebar.SidebarView.OUTLINE;
  1492. break;
  1493. case "attachments":
  1494. view = _pdf_sidebar.SidebarView.ATTACHMENTS;
  1495. break;
  1496. case "layers":
  1497. view = _pdf_sidebar.SidebarView.LAYERS;
  1498. break;
  1499. case "none":
  1500. view = _pdf_sidebar.SidebarView.NONE;
  1501. break;
  1502. default:
  1503. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1504. return;
  1505. }
  1506. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1507. }
  1508. function webViewerNamedAction(evt) {
  1509. switch (evt.action) {
  1510. case "GoToPage":
  1511. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1512. break;
  1513. case "Find":
  1514. if (!PDFViewerApplication.supportsIntegratedFind) {
  1515. PDFViewerApplication.findBar.toggle();
  1516. }
  1517. break;
  1518. case "Print":
  1519. if (PDFViewerApplication.supportsPrinting) {
  1520. webViewerPrint();
  1521. }
  1522. break;
  1523. case "SaveAs":
  1524. webViewerSave();
  1525. break;
  1526. }
  1527. }
  1528. function webViewerPresentationModeChanged({
  1529. active,
  1530. switchInProgress
  1531. }) {
  1532. let state = _ui_utils.PresentationModeState.NORMAL;
  1533. if (switchInProgress) {
  1534. state = _ui_utils.PresentationModeState.CHANGING;
  1535. } else if (active) {
  1536. state = _ui_utils.PresentationModeState.FULLSCREEN;
  1537. }
  1538. PDFViewerApplication.pdfViewer.presentationModeState = state;
  1539. }
  1540. function webViewerSidebarViewChanged(evt) {
  1541. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1542. const store = PDFViewerApplication.store;
  1543. if (store && PDFViewerApplication.isInitialViewSet) {
  1544. store.set("sidebarView", evt.view).catch(function () {});
  1545. }
  1546. }
  1547. function webViewerUpdateViewarea(evt) {
  1548. const location = evt.location,
  1549. store = PDFViewerApplication.store;
  1550. if (store && PDFViewerApplication.isInitialViewSet) {
  1551. store.setMultiple({
  1552. page: location.pageNumber,
  1553. zoom: location.scale,
  1554. scrollLeft: location.left,
  1555. scrollTop: location.top,
  1556. rotation: location.rotation
  1557. }).catch(function () {});
  1558. }
  1559. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1560. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1561. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1562. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1563. const loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1564. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1565. }
  1566. function webViewerScrollModeChanged(evt) {
  1567. const store = PDFViewerApplication.store;
  1568. if (store && PDFViewerApplication.isInitialViewSet) {
  1569. store.set("scrollMode", evt.mode).catch(function () {});
  1570. }
  1571. }
  1572. function webViewerSpreadModeChanged(evt) {
  1573. const store = PDFViewerApplication.store;
  1574. if (store && PDFViewerApplication.isInitialViewSet) {
  1575. store.set("spreadMode", evt.mode).catch(function () {});
  1576. }
  1577. }
  1578. function webViewerResize() {
  1579. const {
  1580. pdfDocument,
  1581. pdfViewer
  1582. } = PDFViewerApplication;
  1583. if (!pdfDocument) {
  1584. return;
  1585. }
  1586. const currentScaleValue = pdfViewer.currentScaleValue;
  1587. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  1588. pdfViewer.currentScaleValue = currentScaleValue;
  1589. }
  1590. pdfViewer.update();
  1591. }
  1592. function webViewerHashchange(evt) {
  1593. const hash = evt.hash;
  1594. if (!hash) {
  1595. return;
  1596. }
  1597. if (!PDFViewerApplication.isInitialViewSet) {
  1598. PDFViewerApplication.initialBookmark = hash;
  1599. } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
  1600. PDFViewerApplication.pdfLinkService.setHash(hash);
  1601. }
  1602. }
  1603. let webViewerFileInputChange, webViewerOpenFile;
  1604. {
  1605. webViewerFileInputChange = function (evt) {
  1606. if (PDFViewerApplication.pdfViewer && PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1607. return;
  1608. }
  1609. const file = evt.fileInput.files[0];
  1610. if (!_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  1611. let url = URL.createObjectURL(file);
  1612. if (file.name) {
  1613. url = {
  1614. url,
  1615. originalUrl: file.name
  1616. };
  1617. }
  1618. PDFViewerApplication.open(url);
  1619. } else {
  1620. PDFViewerApplication.setTitleUsingUrl(file.name);
  1621. const fileReader = new FileReader();
  1622. fileReader.onload = function webViewerChangeFileReaderOnload(event) {
  1623. const buffer = event.target.result;
  1624. PDFViewerApplication.open(new Uint8Array(buffer));
  1625. };
  1626. fileReader.readAsArrayBuffer(file);
  1627. }
  1628. const appConfig = PDFViewerApplication.appConfig;
  1629. appConfig.toolbar.viewBookmark.setAttribute("hidden", "true");
  1630. appConfig.secondaryToolbar.viewBookmarkButton.setAttribute("hidden", "true");
  1631. appConfig.toolbar.download.setAttribute("hidden", "true");
  1632. appConfig.secondaryToolbar.downloadButton.setAttribute("hidden", "true");
  1633. };
  1634. webViewerOpenFile = function (evt) {
  1635. const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  1636. document.getElementById(openFileInputName).click();
  1637. };
  1638. }
  1639. function webViewerPresentationMode() {
  1640. PDFViewerApplication.requestPresentationMode();
  1641. }
  1642. function webViewerPrint() {
  1643. window.print();
  1644. }
  1645. function webViewerDownloadOrSave(sourceEventType) {
  1646. if (PDFViewerApplication.pdfDocument && PDFViewerApplication.pdfDocument.annotationStorage.size > 0) {
  1647. PDFViewerApplication.save({
  1648. sourceEventType
  1649. });
  1650. } else {
  1651. PDFViewerApplication.download({
  1652. sourceEventType
  1653. });
  1654. }
  1655. }
  1656. function webViewerDownload() {
  1657. webViewerDownloadOrSave("download");
  1658. }
  1659. function webViewerSave() {
  1660. webViewerDownloadOrSave("save");
  1661. }
  1662. function webViewerFirstPage() {
  1663. if (PDFViewerApplication.pdfDocument) {
  1664. PDFViewerApplication.page = 1;
  1665. }
  1666. }
  1667. function webViewerLastPage() {
  1668. if (PDFViewerApplication.pdfDocument) {
  1669. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1670. }
  1671. }
  1672. function webViewerNextPage() {
  1673. PDFViewerApplication.page++;
  1674. }
  1675. function webViewerPreviousPage() {
  1676. PDFViewerApplication.page--;
  1677. }
  1678. function webViewerZoomIn() {
  1679. PDFViewerApplication.zoomIn();
  1680. }
  1681. function webViewerZoomOut() {
  1682. PDFViewerApplication.zoomOut();
  1683. }
  1684. function webViewerZoomReset() {
  1685. PDFViewerApplication.zoomReset();
  1686. }
  1687. function webViewerPageNumberChanged(evt) {
  1688. const pdfViewer = PDFViewerApplication.pdfViewer;
  1689. if (evt.value !== "") {
  1690. pdfViewer.currentPageLabel = evt.value;
  1691. }
  1692. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  1693. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1694. }
  1695. }
  1696. function webViewerScaleChanged(evt) {
  1697. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  1698. }
  1699. function webViewerRotateCw() {
  1700. PDFViewerApplication.rotatePages(90);
  1701. }
  1702. function webViewerRotateCcw() {
  1703. PDFViewerApplication.rotatePages(-90);
  1704. }
  1705. function webViewerOptionalContentConfig(evt) {
  1706. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  1707. }
  1708. function webViewerSwitchScrollMode(evt) {
  1709. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  1710. }
  1711. function webViewerSwitchSpreadMode(evt) {
  1712. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  1713. }
  1714. function webViewerDocumentProperties() {
  1715. PDFViewerApplication.pdfDocumentProperties.open();
  1716. }
  1717. function webViewerFind(evt) {
  1718. PDFViewerApplication.findController.executeCommand("find" + evt.type, {
  1719. query: evt.query,
  1720. phraseSearch: evt.phraseSearch,
  1721. caseSensitive: evt.caseSensitive,
  1722. entireWord: evt.entireWord,
  1723. highlightAll: evt.highlightAll,
  1724. findPrevious: evt.findPrevious
  1725. });
  1726. }
  1727. function webViewerFindFromUrlHash(evt) {
  1728. PDFViewerApplication.findController.executeCommand("find", {
  1729. query: evt.query,
  1730. phraseSearch: evt.phraseSearch,
  1731. caseSensitive: false,
  1732. entireWord: false,
  1733. highlightAll: true,
  1734. findPrevious: false
  1735. });
  1736. }
  1737. function webViewerUpdateFindMatchesCount({
  1738. matchesCount
  1739. }) {
  1740. if (PDFViewerApplication.supportsIntegratedFind) {
  1741. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  1742. } else {
  1743. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  1744. }
  1745. }
  1746. function webViewerUpdateFindControlState({
  1747. state,
  1748. previous,
  1749. matchesCount,
  1750. rawQuery
  1751. }) {
  1752. if (PDFViewerApplication.supportsIntegratedFind) {
  1753. PDFViewerApplication.externalServices.updateFindControlState({
  1754. result: state,
  1755. findPrevious: previous,
  1756. matchesCount,
  1757. rawQuery
  1758. });
  1759. } else {
  1760. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  1761. }
  1762. }
  1763. function webViewerScaleChanging(evt) {
  1764. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  1765. PDFViewerApplication.pdfViewer.update();
  1766. }
  1767. function webViewerRotationChanging(evt) {
  1768. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  1769. PDFViewerApplication.forceRendering();
  1770. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  1771. }
  1772. function webViewerPageChanging(evt) {
  1773. const page = evt.pageNumber;
  1774. PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
  1775. PDFViewerApplication.secondaryToolbar.setPageNumber(page);
  1776. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1777. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
  1778. }
  1779. if (typeof Stats !== "undefined" && Stats.enabled) {
  1780. const pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
  1781. if (pageView && pageView.stats) {
  1782. Stats.add(page, pageView.stats);
  1783. }
  1784. }
  1785. }
  1786. function webViewerVisibilityChange(evt) {
  1787. if (document.visibilityState === "visible") {
  1788. setZoomDisabledTimeout();
  1789. }
  1790. }
  1791. let zoomDisabledTimeout = null;
  1792. function setZoomDisabledTimeout() {
  1793. if (zoomDisabledTimeout) {
  1794. clearTimeout(zoomDisabledTimeout);
  1795. }
  1796. zoomDisabledTimeout = setTimeout(function () {
  1797. zoomDisabledTimeout = null;
  1798. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  1799. }
  1800. function webViewerWheel(evt) {
  1801. const {
  1802. pdfViewer,
  1803. supportedMouseWheelZoomModifierKeys
  1804. } = PDFViewerApplication;
  1805. if (pdfViewer.isInPresentationMode) {
  1806. return;
  1807. }
  1808. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  1809. evt.preventDefault();
  1810. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  1811. return;
  1812. }
  1813. const previousScale = pdfViewer.currentScale;
  1814. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  1815. let ticks = 0;
  1816. if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE || evt.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  1817. if (Math.abs(delta) >= 1) {
  1818. ticks = Math.sign(delta);
  1819. } else {
  1820. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  1821. }
  1822. } else {
  1823. const PIXELS_PER_LINE_SCALE = 30;
  1824. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  1825. }
  1826. if (ticks < 0) {
  1827. PDFViewerApplication.zoomOut(-ticks);
  1828. } else if (ticks > 0) {
  1829. PDFViewerApplication.zoomIn(ticks);
  1830. }
  1831. const currentScale = pdfViewer.currentScale;
  1832. if (previousScale !== currentScale) {
  1833. const scaleCorrectionFactor = currentScale / previousScale - 1;
  1834. const rect = pdfViewer.container.getBoundingClientRect();
  1835. const dx = evt.clientX - rect.left;
  1836. const dy = evt.clientY - rect.top;
  1837. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  1838. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  1839. }
  1840. } else {
  1841. setZoomDisabledTimeout();
  1842. }
  1843. }
  1844. function webViewerTouchStart(evt) {
  1845. if (evt.touches.length > 1) {
  1846. evt.preventDefault();
  1847. }
  1848. }
  1849. function webViewerClick(evt) {
  1850. if (PDFViewerApplication.triggerDelayedFallback && PDFViewerApplication.pdfViewer.containsElement(evt.target)) {
  1851. PDFViewerApplication.triggerDelayedFallback();
  1852. }
  1853. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  1854. return;
  1855. }
  1856. const appConfig = PDFViewerApplication.appConfig;
  1857. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  1858. PDFViewerApplication.secondaryToolbar.close();
  1859. }
  1860. }
  1861. function webViewerKeyUp(evt) {
  1862. if (evt.keyCode === 9) {
  1863. if (PDFViewerApplication.triggerDelayedFallback) {
  1864. PDFViewerApplication.triggerDelayedFallback();
  1865. }
  1866. }
  1867. }
  1868. function webViewerKeyDown(evt) {
  1869. if (PDFViewerApplication.overlayManager.active) {
  1870. return;
  1871. }
  1872. let handled = false,
  1873. ensureViewerFocused = false;
  1874. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  1875. const pdfViewer = PDFViewerApplication.pdfViewer;
  1876. const isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
  1877. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  1878. switch (evt.keyCode) {
  1879. case 70:
  1880. if (!PDFViewerApplication.supportsIntegratedFind) {
  1881. PDFViewerApplication.findBar.open();
  1882. handled = true;
  1883. }
  1884. break;
  1885. case 71:
  1886. if (!PDFViewerApplication.supportsIntegratedFind) {
  1887. const findState = PDFViewerApplication.findController.state;
  1888. if (findState) {
  1889. PDFViewerApplication.findController.executeCommand("findagain", {
  1890. query: findState.query,
  1891. phraseSearch: findState.phraseSearch,
  1892. caseSensitive: findState.caseSensitive,
  1893. entireWord: findState.entireWord,
  1894. highlightAll: findState.highlightAll,
  1895. findPrevious: cmd === 5 || cmd === 12
  1896. });
  1897. }
  1898. handled = true;
  1899. }
  1900. break;
  1901. case 61:
  1902. case 107:
  1903. case 187:
  1904. case 171:
  1905. if (!isViewerInPresentationMode) {
  1906. PDFViewerApplication.zoomIn();
  1907. }
  1908. handled = true;
  1909. break;
  1910. case 173:
  1911. case 109:
  1912. case 189:
  1913. if (!isViewerInPresentationMode) {
  1914. PDFViewerApplication.zoomOut();
  1915. }
  1916. handled = true;
  1917. break;
  1918. case 48:
  1919. case 96:
  1920. if (!isViewerInPresentationMode) {
  1921. setTimeout(function () {
  1922. PDFViewerApplication.zoomReset();
  1923. });
  1924. handled = false;
  1925. }
  1926. break;
  1927. case 38:
  1928. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1929. PDFViewerApplication.page = 1;
  1930. handled = true;
  1931. ensureViewerFocused = true;
  1932. }
  1933. break;
  1934. case 40:
  1935. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1936. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1937. handled = true;
  1938. ensureViewerFocused = true;
  1939. }
  1940. break;
  1941. }
  1942. }
  1943. const {
  1944. eventBus
  1945. } = PDFViewerApplication;
  1946. if (cmd === 1 || cmd === 8) {
  1947. switch (evt.keyCode) {
  1948. case 83:
  1949. eventBus.dispatch("download", {
  1950. source: window
  1951. });
  1952. handled = true;
  1953. break;
  1954. case 79:
  1955. {
  1956. eventBus.dispatch("openfile", {
  1957. source: window
  1958. });
  1959. handled = true;
  1960. }
  1961. break;
  1962. }
  1963. }
  1964. if (cmd === 3 || cmd === 10) {
  1965. switch (evt.keyCode) {
  1966. case 80:
  1967. PDFViewerApplication.requestPresentationMode();
  1968. handled = true;
  1969. break;
  1970. case 71:
  1971. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1972. handled = true;
  1973. break;
  1974. }
  1975. }
  1976. if (handled) {
  1977. if (ensureViewerFocused && !isViewerInPresentationMode) {
  1978. pdfViewer.focus();
  1979. }
  1980. evt.preventDefault();
  1981. return;
  1982. }
  1983. const curElement = document.activeElement || document.querySelector(":focus");
  1984. const curElementTagName = curElement && curElement.tagName.toUpperCase();
  1985. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement && curElement.isContentEditable) {
  1986. if (evt.keyCode !== 27) {
  1987. return;
  1988. }
  1989. }
  1990. if (cmd === 0) {
  1991. let turnPage = 0,
  1992. turnOnlyIfPageFit = false;
  1993. switch (evt.keyCode) {
  1994. case 38:
  1995. case 33:
  1996. if (pdfViewer.isVerticalScrollbarEnabled) {
  1997. turnOnlyIfPageFit = true;
  1998. }
  1999. turnPage = -1;
  2000. break;
  2001. case 8:
  2002. if (!isViewerInPresentationMode) {
  2003. turnOnlyIfPageFit = true;
  2004. }
  2005. turnPage = -1;
  2006. break;
  2007. case 37:
  2008. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2009. turnOnlyIfPageFit = true;
  2010. }
  2011. case 75:
  2012. case 80:
  2013. turnPage = -1;
  2014. break;
  2015. case 27:
  2016. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  2017. PDFViewerApplication.secondaryToolbar.close();
  2018. handled = true;
  2019. }
  2020. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  2021. PDFViewerApplication.findBar.close();
  2022. handled = true;
  2023. }
  2024. break;
  2025. case 40:
  2026. case 34:
  2027. if (pdfViewer.isVerticalScrollbarEnabled) {
  2028. turnOnlyIfPageFit = true;
  2029. }
  2030. turnPage = 1;
  2031. break;
  2032. case 13:
  2033. case 32:
  2034. if (!isViewerInPresentationMode) {
  2035. turnOnlyIfPageFit = true;
  2036. }
  2037. turnPage = 1;
  2038. break;
  2039. case 39:
  2040. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2041. turnOnlyIfPageFit = true;
  2042. }
  2043. case 74:
  2044. case 78:
  2045. turnPage = 1;
  2046. break;
  2047. case 36:
  2048. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2049. PDFViewerApplication.page = 1;
  2050. handled = true;
  2051. ensureViewerFocused = true;
  2052. }
  2053. break;
  2054. case 35:
  2055. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2056. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2057. handled = true;
  2058. ensureViewerFocused = true;
  2059. }
  2060. break;
  2061. case 83:
  2062. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2063. break;
  2064. case 72:
  2065. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2066. break;
  2067. case 82:
  2068. PDFViewerApplication.rotatePages(90);
  2069. break;
  2070. case 115:
  2071. PDFViewerApplication.pdfSidebar.toggle();
  2072. break;
  2073. }
  2074. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2075. if (turnPage > 0) {
  2076. if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2077. PDFViewerApplication.page++;
  2078. }
  2079. } else {
  2080. if (PDFViewerApplication.page > 1) {
  2081. PDFViewerApplication.page--;
  2082. }
  2083. }
  2084. handled = true;
  2085. }
  2086. }
  2087. if (cmd === 4) {
  2088. switch (evt.keyCode) {
  2089. case 13:
  2090. case 32:
  2091. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2092. break;
  2093. }
  2094. if (PDFViewerApplication.page > 1) {
  2095. PDFViewerApplication.page--;
  2096. }
  2097. handled = true;
  2098. break;
  2099. case 82:
  2100. PDFViewerApplication.rotatePages(-90);
  2101. break;
  2102. }
  2103. }
  2104. if (!handled && !isViewerInPresentationMode) {
  2105. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2106. ensureViewerFocused = true;
  2107. }
  2108. }
  2109. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2110. pdfViewer.focus();
  2111. }
  2112. if (handled) {
  2113. evt.preventDefault();
  2114. }
  2115. }
  2116. function beforeUnload(evt) {
  2117. evt.preventDefault();
  2118. evt.returnValue = "";
  2119. return false;
  2120. }
  2121. function apiPageLayoutToSpreadMode(layout) {
  2122. switch (layout) {
  2123. case "SinglePage":
  2124. case "OneColumn":
  2125. return _ui_utils.SpreadMode.NONE;
  2126. case "TwoColumnLeft":
  2127. case "TwoPageLeft":
  2128. return _ui_utils.SpreadMode.ODD;
  2129. case "TwoColumnRight":
  2130. case "TwoPageRight":
  2131. return _ui_utils.SpreadMode.EVEN;
  2132. }
  2133. return _ui_utils.SpreadMode.NONE;
  2134. }
  2135. function apiPageModeToSidebarView(mode) {
  2136. switch (mode) {
  2137. case "UseNone":
  2138. return _pdf_sidebar.SidebarView.NONE;
  2139. case "UseThumbs":
  2140. return _pdf_sidebar.SidebarView.THUMBS;
  2141. case "UseOutlines":
  2142. return _pdf_sidebar.SidebarView.OUTLINE;
  2143. case "UseAttachments":
  2144. return _pdf_sidebar.SidebarView.ATTACHMENTS;
  2145. case "UseOC":
  2146. return _pdf_sidebar.SidebarView.LAYERS;
  2147. }
  2148. return _pdf_sidebar.SidebarView.NONE;
  2149. }
  2150. const PDFPrintServiceFactory = {
  2151. instance: {
  2152. supportsPrinting: false,
  2153. createPrintService() {
  2154. throw new Error("Not implemented: createPrintService");
  2155. }
  2156. }
  2157. };
  2158. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;