pdf_page_view.js 22 KB

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