From 29947b5a570e07ca2ea2c2f14d5a3c7bcb838d4c Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Thu, 6 Oct 2016 07:51:45 -0500 Subject: [PATCH] Printing canvases at PDF document size. --- web/pdf_page_view.js | 29 +++++++------------ ...wer-snippet-mozPrintCallback-polyfill.html | 8 ----- web/viewer.css | 7 +++-- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 8a1d197b7..927d9b0d3 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -546,22 +546,18 @@ var PDFPageView = (function PDFPageViewClosure() { 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 = document.createElement('canvas'); - // The logical size of the canvas. - canvas.width = Math.floor(viewport.width) * PRINT_OUTPUT_SCALE; - canvas.height = Math.floor(viewport.height) * PRINT_OUTPUT_SCALE; + // The size of the canvas in pixels for printing. + var PRINT_RESOLUTION = 150; + var PRINT_UNITS = PRINT_RESOLUTION / 72.0; + canvas.width = Math.floor(viewport.width * PRINT_UNITS); + canvas.height = Math.floor(viewport.height * PRINT_UNITS); - // The rendered size of the canvas, relative to the size of canvasWrapper. - canvas.style.width = (PRINT_OUTPUT_SCALE * 100) + '%'; - - var cssScale = 'scale(' + (1 / PRINT_OUTPUT_SCALE) + ', ' + - (1 / PRINT_OUTPUT_SCALE) + ')'; - CustomStyle.setProp('transform' , canvas, cssScale); - CustomStyle.setProp('transformOrigin' , canvas, '0% 0%'); + // The physical size of the canvas as specified by the PDF document. + canvas.style.width = Math.floor(viewport.width * CSS_UNITS) + 'px'; + canvas.style.height = Math.floor(viewport.height * CSS_UNITS) + 'px'; var canvasWrapper = document.createElement('div'); canvasWrapper.appendChild(canvas); @@ -574,15 +570,10 @@ var PDFPageView = (function PDFPageViewClosure() { ctx.fillStyle = 'rgb(255, 255, 255)'; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.restore(); -//#if !(MOZCENTRAL || FIREFOX) - // Used by the mozCurrentTransform polyfill in src/display/canvas.js. - ctx._transformMatrix = - [PRINT_OUTPUT_SCALE, 0, 0, PRINT_OUTPUT_SCALE, 0, 0]; -//#endif - ctx.scale(PRINT_OUTPUT_SCALE, PRINT_OUTPUT_SCALE); var renderContext = { canvasContext: ctx, + transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0], viewport: viewport, intent: 'print' }; diff --git a/web/viewer-snippet-mozPrintCallback-polyfill.html b/web/viewer-snippet-mozPrintCallback-polyfill.html index c45252371..ebf2e3419 100644 --- a/web/viewer-snippet-mozPrintCallback-polyfill.html +++ b/web/viewer-snippet-mozPrintCallback-polyfill.html @@ -1,12 +1,4 @@