Skip to content

Commit

Permalink
Removes mozPrintCallback polyfill, converts canvas to PNG.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Oct 8, 2016
1 parent 24a7a58 commit d48f9e4
Show file tree
Hide file tree
Showing 9 changed files with 338 additions and 279 deletions.
8 changes: 4 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@ function createWebBundle(defines) {
amdName = 'pdfjs-dist/web/viewer';
outputName = 'viewer.js';
template = 'web/viewer.js';
files = ['app.js', 'firefox_print_service.js'];
files = ['app.js'];
if (defines.FIREFOX || defines.MOZCENTRAL) {
files.push('firefoxcom.js');
files.push('firefoxcom.js', 'firefox_print_service.js');
} else if (defines.CHROME) {
files.push('chromecom.js', 'mozPrintCallback_polyfill.js');
files.push('chromecom.js', 'pdf_print_service.js');
} else if (defines.GENERIC) {
files.push('mozPrintCallback_polyfill.js');
files.push('pdf_print_service.js');
}
}

Expand Down
7 changes: 7 additions & 0 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,13 @@ var PDFViewerApplication = {
},

beforePrint: function pdfViewSetupBeforePrint() {
if (this.printService) {
// There is no way to suppress beforePrint/afterPrint events,
// but PDFPrintService may generate double events -- this will ignore
// the second event that will be coming from native window.print().
return;
}

if (!this.supportsPrinting) {
var printMessage = mozL10n.get('printing_not_supported', null,
'Warning: Printing is not fully supported by this browser.');
Expand Down
33 changes: 0 additions & 33 deletions web/firefox_print_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
this.pdfDocument = pdfDocument;
this.pagesOverview = pagesOverview;
this.printContainer = printContainer;
this.pageStyleSheet = null;
}

FirefoxPrintService.prototype = {
Expand All @@ -95,45 +94,13 @@
var body = document.querySelector('body');
body.setAttribute('data-pdfjsprinting', true);

var hasEqualPageSizes = this.pagesOverview.every(function (size) {
return size.width === this.pagesOverview[0].width &&
size.height === this.pagesOverview[0].height;
}, this);
if (!hasEqualPageSizes) {
console.warn('Not all pages have the same size. The printed ' +
'result may be incorrect!');
}

// Insert a @page + size rule to make sure that the page size is correctly
// set. Note that we assume that all pages have the same size, because
// variable-size pages are not supported yet (e.g. in Chrome & Firefox).
// TODO(robwu): Use named pages when size calculation bugs get resolved
// (e.g. https://crbug.com/355116) AND when support for named pages is
// added (http://www.w3.org/TR/css3-page/#using-named-pages).
// In browsers where @page + size is not supported (such as Firefox,
// https://bugzil.la/851441), the next stylesheet will be ignored and the
// user has to select the correct paper size in the UI if wanted.
this.pageStyleSheet = document.createElement('style');
var pageSize = this.pagesOverview[0];
this.pageStyleSheet.textContent =
// "size:<width> <height>" is what we need. But also add "A4" because
// Firefox incorrectly reports support for the other value.
'@supports ((size:A4) and (size:1pt 1pt)) {' +
'@page { size: ' + pageSize.width + 'pt ' + pageSize.height + 'pt;}' +
'}';
body.appendChild(this.pageStyleSheet);

for (var i = 0, ii = this.pagesOverview.length; i < ii; ++i) {
composePage(pdfDocument, i + 1, this.pagesOverview[i], printContainer);
}
},

destroy: function () {
this.printContainer.textContent = '';
if (this.pageStyleSheet && this.pageStyleSheet.parentNode) {
this.pageStyleSheet.parentNode.removeChild(this.pageStyleSheet);
this.pageStyleSheet = null;
}
}
};

Expand Down
165 changes: 0 additions & 165 deletions web/mozPrintCallback_polyfill.js

This file was deleted.

Loading

0 comments on commit d48f9e4

Please sign in to comment.