From 60209f6b43bb7f9ad749806526e97cf172771bbd Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 13 Nov 2012 16:57:23 -0800 Subject: [PATCH] Use high dpi display hack for printing too. --- web/viewer.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index dc0a416d4..0a810a85e 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -2089,12 +2089,18 @@ var PageView = function pageView(container, pdfPage, id, scale, this.beforePrint = function pageViewBeforePrint() { var pdfPage = this.pdfPage; var viewport = pdfPage.getViewport(1); - + // Use the same hack we use for high dpi displays for printing to get better + // output until bug 811002 is fixed in FF. + var PRINT_OUTPUT_SCALE = 2; 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'; + canvas.width = Math.floor(viewport.width) * PRINT_OUTPUT_SCALE; + canvas.height = Math.floor(viewport.height) * PRINT_OUTPUT_SCALE; + canvas.style.width = (PRINT_OUTPUT_SCALE * viewport.width) + 'pt'; + canvas.style.height = (PRINT_OUTPUT_SCALE * viewport.height) + 'pt'; + var cssScale = 'scale(' + (1 / PRINT_OUTPUT_SCALE) + ', ' + + (1 / PRINT_OUTPUT_SCALE) + ')'; + CustomStyle.setProp('transform' , canvas, cssScale); + CustomStyle.setProp('transformOrigin' , canvas, '0% 0%'); var printContainer = document.getElementById('printContainer'); printContainer.appendChild(canvas); @@ -2102,6 +2108,13 @@ var PageView = function pageView(container, pdfPage, id, scale, var self = this; canvas.mozPrintCallback = function(obj) { var ctx = obj.context; + + ctx.save(); + ctx.fillStyle = 'rgb(255, 255, 255)'; + ctx.fillRect(0, 0, canvas.width, canvas.height); + ctx.restore(); + ctx.scale(PRINT_OUTPUT_SCALE, PRINT_OUTPUT_SCALE); + var renderContext = { canvasContext: ctx, viewport: viewport