pdf_page_view.js 23 KB

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