pdf_page_view.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 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.PDFPageView = void 0;
  27. var _ui_utils = require("./ui_utils.js");
  28. var _pdf = require("../pdf");
  29. var _l10n_utils = require("./l10n_utils.js");
  30. var _pdf_rendering_queue = require("./pdf_rendering_queue.js");
  31. var _viewer_compatibility = require("./viewer_compatibility.js");
  32. const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
  33. class PDFPageView {
  34. constructor(options) {
  35. const container = options.container;
  36. const defaultViewport = options.defaultViewport;
  37. this.id = options.id;
  38. this.renderingId = "page" + this.id;
  39. this.pdfPage = null;
  40. this.pageLabel = null;
  41. this.rotation = 0;
  42. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  43. this.viewport = defaultViewport;
  44. this.pdfPageRotate = defaultViewport.rotation;
  45. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  46. this.hasRestrictedScaling = false;
  47. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  48. this.imageResourcesPath = options.imageResourcesPath || "";
  49. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  50. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  51. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  52. this.eventBus = options.eventBus;
  53. this.renderingQueue = options.renderingQueue;
  54. this.textLayerFactory = options.textLayerFactory;
  55. this.annotationLayerFactory = options.annotationLayerFactory;
  56. this.xfaLayerFactory = options.xfaLayerFactory;
  57. this.structTreeLayerFactory = options.structTreeLayerFactory;
  58. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  59. this.l10n = options.l10n || _l10n_utils.NullL10n;
  60. this.paintTask = null;
  61. this.paintedViewportMap = new WeakMap();
  62. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  63. this.resume = null;
  64. this._renderError = null;
  65. this.annotationLayer = null;
  66. this.textLayer = null;
  67. this.zoomLayer = null;
  68. this.xfaLayer = null;
  69. this.structTreeLayer = null;
  70. const div = document.createElement("div");
  71. div.className = "page";
  72. div.style.width = Math.floor(this.viewport.width) + "px";
  73. div.style.height = Math.floor(this.viewport.height) + "px";
  74. div.setAttribute("data-page-number", this.id);
  75. div.setAttribute("role", "region");
  76. this.l10n.get("page_landmark", {
  77. page: this.id
  78. }).then(msg => {
  79. div.setAttribute("aria-label", msg);
  80. });
  81. this.div = div;
  82. container.appendChild(div);
  83. }
  84. setPdfPage(pdfPage) {
  85. this.pdfPage = pdfPage;
  86. this.pdfPageRotate = pdfPage.rotate;
  87. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  88. this.viewport = pdfPage.getViewport({
  89. scale: this.scale * _ui_utils.CSS_UNITS,
  90. rotation: totalRotation
  91. });
  92. this.reset();
  93. }
  94. destroy() {
  95. this.reset();
  96. if (this.pdfPage) {
  97. this.pdfPage.cleanup();
  98. }
  99. }
  100. async _renderAnnotationLayer() {
  101. let error = null;
  102. try {
  103. await this.annotationLayer.render(this.viewport, "display");
  104. } catch (ex) {
  105. error = ex;
  106. } finally {
  107. this.eventBus.dispatch("annotationlayerrendered", {
  108. source: this,
  109. pageNumber: this.id,
  110. error
  111. });
  112. }
  113. }
  114. async _renderXfaLayer() {
  115. let error = null;
  116. try {
  117. await this.xfaLayer.render(this.viewport, "display");
  118. } catch (ex) {
  119. error = ex;
  120. } finally {
  121. this.eventBus.dispatch("xfalayerrendered", {
  122. source: this,
  123. pageNumber: this.id,
  124. error
  125. });
  126. }
  127. }
  128. _resetZoomLayer(removeFromDOM = false) {
  129. if (!this.zoomLayer) {
  130. return;
  131. }
  132. const zoomLayerCanvas = this.zoomLayer.firstChild;
  133. this.paintedViewportMap.delete(zoomLayerCanvas);
  134. zoomLayerCanvas.width = 0;
  135. zoomLayerCanvas.height = 0;
  136. if (removeFromDOM) {
  137. this.zoomLayer.remove();
  138. }
  139. this.zoomLayer = null;
  140. }
  141. reset(keepZoomLayer = false, keepAnnotations = false) {
  142. this.cancelRendering(keepAnnotations);
  143. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  144. const div = this.div;
  145. div.style.width = Math.floor(this.viewport.width) + "px";
  146. div.style.height = Math.floor(this.viewport.height) + "px";
  147. const childNodes = div.childNodes;
  148. const currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
  149. const currentAnnotationNode = keepAnnotations && this.annotationLayer?.div || null;
  150. const currentXfaLayerNode = this.xfaLayer?.div || null;
  151. for (let i = childNodes.length - 1; i >= 0; i--) {
  152. const node = childNodes[i];
  153. if (currentZoomLayerNode === node || currentAnnotationNode === node || currentXfaLayerNode === node) {
  154. continue;
  155. }
  156. div.removeChild(node);
  157. }
  158. div.removeAttribute("data-loaded");
  159. if (currentAnnotationNode) {
  160. this.annotationLayer.hide();
  161. } else if (this.annotationLayer) {
  162. this.annotationLayer.cancel();
  163. this.annotationLayer = null;
  164. }
  165. if (!currentZoomLayerNode) {
  166. if (this.canvas) {
  167. this.paintedViewportMap.delete(this.canvas);
  168. this.canvas.width = 0;
  169. this.canvas.height = 0;
  170. delete this.canvas;
  171. }
  172. this._resetZoomLayer();
  173. }
  174. if (this.svg) {
  175. this.paintedViewportMap.delete(this.svg);
  176. delete this.svg;
  177. }
  178. this.loadingIconDiv = document.createElement("div");
  179. this.loadingIconDiv.className = "loadingIcon";
  180. this.loadingIconDiv.setAttribute("role", "img");
  181. this.l10n.get("loading").then(msg => {
  182. this.loadingIconDiv?.setAttribute("aria-label", msg);
  183. });
  184. div.appendChild(this.loadingIconDiv);
  185. }
  186. update(scale, rotation, optionalContentConfigPromise = null) {
  187. this.scale = scale || this.scale;
  188. if (typeof rotation !== "undefined") {
  189. this.rotation = rotation;
  190. }
  191. if (optionalContentConfigPromise instanceof Promise) {
  192. this._optionalContentConfigPromise = optionalContentConfigPromise;
  193. }
  194. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  195. this.viewport = this.viewport.clone({
  196. scale: this.scale * _ui_utils.CSS_UNITS,
  197. rotation: totalRotation
  198. });
  199. if (this.svg) {
  200. this.cssTransform(this.svg, true);
  201. this.eventBus.dispatch("pagerendered", {
  202. source: this,
  203. pageNumber: this.id,
  204. cssTransform: true,
  205. timestamp: performance.now(),
  206. error: this._renderError
  207. });
  208. return;
  209. }
  210. let isScalingRestricted = false;
  211. if (this.canvas && this.maxCanvasPixels > 0) {
  212. const outputScale = this.outputScale;
  213. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  214. isScalingRestricted = true;
  215. }
  216. }
  217. if (this.canvas) {
  218. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  219. this.cssTransform(this.canvas, true);
  220. this.eventBus.dispatch("pagerendered", {
  221. source: this,
  222. pageNumber: this.id,
  223. cssTransform: true,
  224. timestamp: performance.now(),
  225. error: this._renderError
  226. });
  227. return;
  228. }
  229. if (!this.zoomLayer && !this.canvas.hidden) {
  230. this.zoomLayer = this.canvas.parentNode;
  231. this.zoomLayer.style.position = "absolute";
  232. }
  233. }
  234. if (this.zoomLayer) {
  235. this.cssTransform(this.zoomLayer.firstChild);
  236. }
  237. this.reset(true, true);
  238. }
  239. cancelRendering(keepAnnotations = false) {
  240. if (this.paintTask) {
  241. this.paintTask.cancel();
  242. this.paintTask = null;
  243. }
  244. this.resume = null;
  245. if (this.textLayer) {
  246. this.textLayer.cancel();
  247. this.textLayer = null;
  248. }
  249. if (!keepAnnotations && this.annotationLayer) {
  250. this.annotationLayer.cancel();
  251. this.annotationLayer = null;
  252. }
  253. if (this._onTextLayerRendered) {
  254. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  255. this._onTextLayerRendered = null;
  256. }
  257. }
  258. cssTransform(target, redrawAnnotations = false) {
  259. const width = this.viewport.width;
  260. const height = this.viewport.height;
  261. const div = this.div;
  262. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  263. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  264. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  265. const absRotation = Math.abs(relativeRotation);
  266. let scaleX = 1,
  267. scaleY = 1;
  268. if (absRotation === 90 || absRotation === 270) {
  269. scaleX = height / width;
  270. scaleY = width / height;
  271. }
  272. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  273. if (this.textLayer) {
  274. const textLayerViewport = this.textLayer.viewport;
  275. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  276. const textAbsRotation = Math.abs(textRelativeRotation);
  277. let scale = width / textLayerViewport.width;
  278. if (textAbsRotation === 90 || textAbsRotation === 270) {
  279. scale = width / textLayerViewport.height;
  280. }
  281. const textLayerDiv = this.textLayer.textLayerDiv;
  282. let transX, transY;
  283. switch (textAbsRotation) {
  284. case 0:
  285. transX = transY = 0;
  286. break;
  287. case 90:
  288. transX = 0;
  289. transY = "-" + textLayerDiv.style.height;
  290. break;
  291. case 180:
  292. transX = "-" + textLayerDiv.style.width;
  293. transY = "-" + textLayerDiv.style.height;
  294. break;
  295. case 270:
  296. transX = "-" + textLayerDiv.style.width;
  297. transY = 0;
  298. break;
  299. default:
  300. console.error("Bad rotation value.");
  301. break;
  302. }
  303. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  304. textLayerDiv.style.transformOrigin = "0% 0%";
  305. }
  306. if (redrawAnnotations && this.annotationLayer) {
  307. this._renderAnnotationLayer();
  308. }
  309. if (this.xfaLayer) {
  310. this._renderXfaLayer();
  311. }
  312. }
  313. get width() {
  314. return this.viewport.width;
  315. }
  316. get height() {
  317. return this.viewport.height;
  318. }
  319. getPagePoint(x, y) {
  320. return this.viewport.convertToPdfPoint(x, y);
  321. }
  322. draw() {
  323. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  324. console.error("Must be in new state before drawing");
  325. this.reset();
  326. }
  327. const {
  328. div,
  329. pdfPage
  330. } = this;
  331. if (!pdfPage) {
  332. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  333. if (this.loadingIconDiv) {
  334. div.removeChild(this.loadingIconDiv);
  335. delete this.loadingIconDiv;
  336. }
  337. return Promise.reject(new Error("pdfPage is not loaded"));
  338. }
  339. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  340. const canvasWrapper = document.createElement("div");
  341. canvasWrapper.style.width = div.style.width;
  342. canvasWrapper.style.height = div.style.height;
  343. canvasWrapper.classList.add("canvasWrapper");
  344. if (this.annotationLayer?.div) {
  345. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  346. } else {
  347. div.appendChild(canvasWrapper);
  348. }
  349. let textLayer = null;
  350. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  351. const textLayerDiv = document.createElement("div");
  352. textLayerDiv.className = "textLayer";
  353. textLayerDiv.style.width = canvasWrapper.style.width;
  354. textLayerDiv.style.height = canvasWrapper.style.height;
  355. if (this.annotationLayer?.div) {
  356. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  357. } else {
  358. div.appendChild(textLayerDiv);
  359. }
  360. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus);
  361. }
  362. this.textLayer = textLayer;
  363. let renderContinueCallback = null;
  364. if (this.renderingQueue) {
  365. renderContinueCallback = cont => {
  366. if (!this.renderingQueue.isHighestPriority(this)) {
  367. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  368. this.resume = () => {
  369. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  370. cont();
  371. };
  372. return;
  373. }
  374. cont();
  375. };
  376. }
  377. const finishPaintTask = async (error = null) => {
  378. if (paintTask === this.paintTask) {
  379. this.paintTask = null;
  380. }
  381. if (error instanceof _pdf.RenderingCancelledException) {
  382. this._renderError = null;
  383. return;
  384. }
  385. this._renderError = error;
  386. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  387. if (this.loadingIconDiv) {
  388. div.removeChild(this.loadingIconDiv);
  389. delete this.loadingIconDiv;
  390. }
  391. this._resetZoomLayer(true);
  392. this.eventBus.dispatch("pagerendered", {
  393. source: this,
  394. pageNumber: this.id,
  395. cssTransform: false,
  396. timestamp: performance.now(),
  397. error: this._renderError
  398. });
  399. if (error) {
  400. throw error;
  401. }
  402. };
  403. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  404. paintTask.onRenderContinue = renderContinueCallback;
  405. this.paintTask = paintTask;
  406. const resultPromise = paintTask.promise.then(() => {
  407. return finishPaintTask(null).then(() => {
  408. if (textLayer) {
  409. const readableStream = pdfPage.streamTextContent({
  410. normalizeWhitespace: true,
  411. includeMarkedContent: true
  412. });
  413. textLayer.setTextContentStream(readableStream);
  414. textLayer.render();
  415. }
  416. });
  417. }, function (reason) {
  418. return finishPaintTask(reason);
  419. });
  420. if (this.annotationLayerFactory) {
  421. if (!this.annotationLayer) {
  422. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, null, this.imageResourcesPath, this.renderInteractiveForms, this.l10n, null, null, null);
  423. }
  424. this._renderAnnotationLayer();
  425. }
  426. if (this.xfaLayerFactory) {
  427. if (!this.xfaLayer) {
  428. this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder(div, pdfPage, null);
  429. }
  430. this._renderXfaLayer();
  431. }
  432. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  433. this._onTextLayerRendered = event => {
  434. if (event.pageNumber !== this.id) {
  435. return;
  436. }
  437. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  438. this._onTextLayerRendered = null;
  439. if (!this.canvas) {
  440. return;
  441. }
  442. this.pdfPage.getStructTree().then(tree => {
  443. if (!tree) {
  444. return;
  445. }
  446. if (!this.canvas) {
  447. return;
  448. }
  449. const treeDom = this.structTreeLayer.render(tree);
  450. treeDom.classList.add("structTree");
  451. this.canvas.appendChild(treeDom);
  452. });
  453. };
  454. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  455. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder(pdfPage);
  456. }
  457. div.setAttribute("data-loaded", true);
  458. this.eventBus.dispatch("pagerender", {
  459. source: this,
  460. pageNumber: this.id
  461. });
  462. return resultPromise;
  463. }
  464. paintOnCanvas(canvasWrapper) {
  465. const renderCapability = (0, _pdf.createPromiseCapability)();
  466. const result = {
  467. promise: renderCapability.promise,
  468. onRenderContinue(cont) {
  469. cont();
  470. },
  471. cancel() {
  472. renderTask.cancel();
  473. }
  474. };
  475. const viewport = this.viewport;
  476. const canvas = document.createElement("canvas");
  477. canvas.hidden = true;
  478. let isCanvasHidden = true;
  479. const showCanvas = function () {
  480. if (isCanvasHidden) {
  481. canvas.hidden = false;
  482. isCanvasHidden = false;
  483. }
  484. };
  485. canvasWrapper.appendChild(canvas);
  486. this.canvas = canvas;
  487. canvas.mozOpaque = true;
  488. const ctx = canvas.getContext("2d", {
  489. alpha: false
  490. });
  491. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  492. this.outputScale = outputScale;
  493. if (this.useOnlyCssZoom) {
  494. const actualSizeViewport = viewport.clone({
  495. scale: _ui_utils.CSS_UNITS
  496. });
  497. outputScale.sx *= actualSizeViewport.width / viewport.width;
  498. outputScale.sy *= actualSizeViewport.height / viewport.height;
  499. outputScale.scaled = true;
  500. }
  501. if (this.maxCanvasPixels > 0) {
  502. const pixelsInViewport = viewport.width * viewport.height;
  503. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  504. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  505. outputScale.sx = maxScale;
  506. outputScale.sy = maxScale;
  507. outputScale.scaled = true;
  508. this.hasRestrictedScaling = true;
  509. } else {
  510. this.hasRestrictedScaling = false;
  511. }
  512. }
  513. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  514. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  515. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  516. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  517. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  518. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  519. this.paintedViewportMap.set(canvas, viewport);
  520. const transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  521. const renderContext = {
  522. canvasContext: ctx,
  523. transform,
  524. viewport: this.viewport,
  525. renderInteractiveForms: this.renderInteractiveForms,
  526. optionalContentConfigPromise: this._optionalContentConfigPromise
  527. };
  528. const renderTask = this.pdfPage.render(renderContext);
  529. renderTask.onContinue = function (cont) {
  530. showCanvas();
  531. if (result.onRenderContinue) {
  532. result.onRenderContinue(cont);
  533. } else {
  534. cont();
  535. }
  536. };
  537. renderTask.promise.then(function () {
  538. showCanvas();
  539. renderCapability.resolve(undefined);
  540. }, function (error) {
  541. showCanvas();
  542. renderCapability.reject(error);
  543. });
  544. return result;
  545. }
  546. paintOnSvg(wrapper) {
  547. let cancelled = false;
  548. const ensureNotCancelled = () => {
  549. if (cancelled) {
  550. throw new _pdf.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  551. }
  552. };
  553. const pdfPage = this.pdfPage;
  554. const actualSizeViewport = this.viewport.clone({
  555. scale: _ui_utils.CSS_UNITS
  556. });
  557. const promise = pdfPage.getOperatorList().then(opList => {
  558. ensureNotCancelled();
  559. const svgGfx = new _pdf.SVGGraphics(pdfPage.commonObjs, pdfPage.objs, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  560. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  561. ensureNotCancelled();
  562. this.svg = svg;
  563. this.paintedViewportMap.set(svg, actualSizeViewport);
  564. svg.style.width = wrapper.style.width;
  565. svg.style.height = wrapper.style.height;
  566. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  567. wrapper.appendChild(svg);
  568. });
  569. });
  570. return {
  571. promise,
  572. onRenderContinue(cont) {
  573. cont();
  574. },
  575. cancel() {
  576. cancelled = true;
  577. }
  578. };
  579. }
  580. setPageLabel(label) {
  581. this.pageLabel = typeof label === "string" ? label : null;
  582. if (this.pageLabel !== null) {
  583. this.div.setAttribute("data-page-label", this.pageLabel);
  584. } else {
  585. this.div.removeAttribute("data-page-label");
  586. }
  587. }
  588. }
  589. exports.PDFPageView = PDFPageView;