|
|
|
@ -379,6 +379,11 @@ var PDFView = {
@@ -379,6 +379,11 @@ var PDFView = {
|
|
|
|
|
return currentPageNumber; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
get supportsPrinting() { |
|
|
|
|
var canvas = document.createElement('canvas'); |
|
|
|
|
return 'mozPrintCallback' in canvas; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
open: function pdfViewOpen(url, scale, password) { |
|
|
|
|
var parameters = {password: password}; |
|
|
|
|
if (typeof url === 'string') { // URL
|
|
|
|
@ -1041,6 +1046,22 @@ var PDFView = {
@@ -1041,6 +1046,22 @@ var PDFView = {
|
|
|
|
|
params[unescape(key)] = unescape(value); |
|
|
|
|
} |
|
|
|
|
return params; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
beforePrint: function pdfViewSetupBeforePrint() { |
|
|
|
|
if (!this.supportsPrinting) { |
|
|
|
|
alert('Printing is not supported by this browser.'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
for (var i = 0, ii = this.pages.length; i < ii; ++i) { |
|
|
|
|
this.pages[i].beforePrint(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
afterPrint: function pdfViewSetupAfterPrint() { |
|
|
|
|
var div = document.getElementById('printContainer'); |
|
|
|
|
while (div.hasChildNodes()) |
|
|
|
|
div.removeChild(div.lastChild); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -1360,6 +1381,40 @@ var PageView = function pageView(container, pdfPage, id, scale,
@@ -1360,6 +1381,40 @@ var PageView = function pageView(container, pdfPage, id, scale,
|
|
|
|
|
div.setAttribute('data-loaded', true); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.beforePrint = function pageViewBeforePrint() { |
|
|
|
|
var pdfPage = this.pdfPage; |
|
|
|
|
var viewport = pdfPage.getViewport(1); |
|
|
|
|
|
|
|
|
|
var canvas = this.canvas = document.createElement('canvas'); |
|
|
|
|
canvas.width = viewport.width; |
|
|
|
|
canvas.height = viewport.height; |
|
|
|
|
canvas.style.width = viewport.width + 'pt'; |
|
|
|
|
canvas.style.height = viewport.height + 'pt'; |
|
|
|
|
|
|
|
|
|
var printContainer = document.getElementById('printContainer'); |
|
|
|
|
printContainer.appendChild(canvas); |
|
|
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
canvas.mozPrintCallback = function(obj) { |
|
|
|
|
var ctx = obj.context; |
|
|
|
|
var renderContext = { |
|
|
|
|
canvasContext: ctx, |
|
|
|
|
viewport: viewport |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
pdfPage.render(renderContext).then(function() { |
|
|
|
|
// Tell the printEngine that rendering this canvas/page has finished.
|
|
|
|
|
obj.done(); |
|
|
|
|
self.pdfPage.destroy(); |
|
|
|
|
}, function(error) { |
|
|
|
|
console.error(error); |
|
|
|
|
// Tell the printEngine that rendering this canvas/page has failed.
|
|
|
|
|
// This will make the print proces stop.
|
|
|
|
|
obj.abort(); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.updateStats = function pageViewUpdateStats() { |
|
|
|
|
if (PDFJS.pdfBug && Stats.enabled) { |
|
|
|
|
var stats = this.stats; |
|
|
|
@ -1960,3 +2015,11 @@ window.addEventListener('keydown', function keydown(evt) {
@@ -1960,3 +2015,11 @@ window.addEventListener('keydown', function keydown(evt) {
|
|
|
|
|
evt.preventDefault(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
window.addEventListener('beforeprint', function beforePrint(evt) { |
|
|
|
|
PDFView.beforePrint(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
window.addEventListener('afterprint', function afterPrint(evt) { |
|
|
|
|
PDFView.afterPrint(); |
|
|
|
|
}); |
|
|
|
|