1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | 'use strict';
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.FirefoxPrintService = undefined;
|
28 |
|
29 | var _ui_utils = require('./ui_utils');
|
30 |
|
31 | var _app = require('./app');
|
32 |
|
33 | var _pdf = require('../pdf');
|
34 |
|
35 | function composePage(pdfDocument, pageNumber, size, printContainer) {
|
36 | var canvas = document.createElement('canvas');
|
37 | var PRINT_RESOLUTION = 150;
|
38 | var PRINT_UNITS = PRINT_RESOLUTION / 72.0;
|
39 | canvas.width = Math.floor(size.width * PRINT_UNITS);
|
40 | canvas.height = Math.floor(size.height * PRINT_UNITS);
|
41 | canvas.style.width = Math.floor(size.width * _ui_utils.CSS_UNITS) + 'px';
|
42 | canvas.style.height = Math.floor(size.height * _ui_utils.CSS_UNITS) + 'px';
|
43 | var canvasWrapper = document.createElement('div');
|
44 | canvasWrapper.appendChild(canvas);
|
45 | printContainer.appendChild(canvasWrapper);
|
46 | canvas.mozPrintCallback = function (obj) {
|
47 | var ctx = obj.context;
|
48 | ctx.save();
|
49 | ctx.fillStyle = 'rgb(255, 255, 255)';
|
50 | ctx.fillRect(0, 0, canvas.width, canvas.height);
|
51 | ctx.restore();
|
52 | pdfDocument.getPage(pageNumber).then(function (pdfPage) {
|
53 | var renderContext = {
|
54 | canvasContext: ctx,
|
55 | transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
|
56 | viewport: pdfPage.getViewport(1, size.rotation),
|
57 | intent: 'print'
|
58 | };
|
59 | return pdfPage.render(renderContext).promise;
|
60 | }).then(function () {
|
61 | obj.done();
|
62 | }, function (error) {
|
63 | console.error(error);
|
64 | if ('abort' in obj) {
|
65 | obj.abort();
|
66 | } else {
|
67 | obj.done();
|
68 | }
|
69 | });
|
70 | };
|
71 | }
|
72 | function FirefoxPrintService(pdfDocument, pagesOverview, printContainer) {
|
73 | this.pdfDocument = pdfDocument;
|
74 | this.pagesOverview = pagesOverview;
|
75 | this.printContainer = printContainer;
|
76 | }
|
77 | FirefoxPrintService.prototype = {
|
78 | layout: function layout() {
|
79 | var pdfDocument = this.pdfDocument;
|
80 | var printContainer = this.printContainer;
|
81 | var body = document.querySelector('body');
|
82 | body.setAttribute('data-pdfjsprinting', true);
|
83 | for (var i = 0, ii = this.pagesOverview.length; i < ii; ++i) {
|
84 | composePage(pdfDocument, i + 1, this.pagesOverview[i], printContainer);
|
85 | }
|
86 | },
|
87 | destroy: function destroy() {
|
88 | this.printContainer.textContent = '';
|
89 | }
|
90 | };
|
91 | _app.PDFPrintServiceFactory.instance = {
|
92 | get supportsPrinting() {
|
93 | var canvas = document.createElement('canvas');
|
94 | var value = 'mozPrintCallback' in canvas;
|
95 | return (0, _pdf.shadow)(this, 'supportsPrinting', value);
|
96 | },
|
97 | createPrintService: function createPrintService(pdfDocument, pagesOverview, printContainer) {
|
98 | return new FirefoxPrintService(pdfDocument, pagesOverview, printContainer);
|
99 | }
|
100 | };
|
101 | exports.FirefoxPrintService = FirefoxPrintService; |
\ | No newline at end of file |