Use let/const instead of var in the printing code

This commit is contained in:
Jonas Jenwald 2017-10-22 16:13:14 +02:00
parent a0ec980e63
commit d14cb5eb27
2 changed files with 50 additions and 50 deletions

View file

@ -19,11 +19,11 @@ import { shadow } from 'pdfjs-lib';
// Creates a placeholder with div and canvas with right size for the page.
function composePage(pdfDocument, pageNumber, size, printContainer) {
var canvas = document.createElement('canvas');
let canvas = document.createElement('canvas');
// The size of the canvas in pixels for printing.
var PRINT_RESOLUTION = 150;
var PRINT_UNITS = PRINT_RESOLUTION / 72.0;
const PRINT_RESOLUTION = 150;
const PRINT_UNITS = PRINT_RESOLUTION / 72.0;
canvas.width = Math.floor(size.width * PRINT_UNITS);
canvas.height = Math.floor(size.height * PRINT_UNITS);
@ -31,21 +31,21 @@ function composePage(pdfDocument, pageNumber, size, printContainer) {
canvas.style.width = Math.floor(size.width * CSS_UNITS) + 'px';
canvas.style.height = Math.floor(size.height * CSS_UNITS) + 'px';
var canvasWrapper = document.createElement('div');
let canvasWrapper = document.createElement('div');
canvasWrapper.appendChild(canvas);
printContainer.appendChild(canvasWrapper);
canvas.mozPrintCallback = function(obj) {
// Printing/rendering the page.
var ctx = obj.context;
let ctx = obj.context;
ctx.save();
ctx.fillStyle = 'rgb(255, 255, 255)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.restore();
pdfDocument.getPage(pageNumber).then(function (pdfPage) {
var renderContext = {
pdfDocument.getPage(pageNumber).then(function(pdfPage) {
let renderContext = {
canvasContext: ctx,
transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
viewport: pdfPage.getViewport(1, size.rotation),
@ -76,12 +76,12 @@ function FirefoxPrintService(pdfDocument, pagesOverview, printContainer) {
FirefoxPrintService.prototype = {
layout() {
var pdfDocument = this.pdfDocument;
var printContainer = this.printContainer;
var body = document.querySelector('body');
let pdfDocument = this.pdfDocument;
let printContainer = this.printContainer;
let body = document.querySelector('body');
body.setAttribute('data-pdfjsprinting', true);
for (var i = 0, ii = this.pagesOverview.length; i < ii; ++i) {
for (let i = 0, ii = this.pagesOverview.length; i < ii; ++i) {
composePage(pdfDocument, i + 1, this.pagesOverview[i], printContainer);
}
},
@ -93,8 +93,8 @@ FirefoxPrintService.prototype = {
PDFPrintServiceFactory.instance = {
get supportsPrinting() {
var canvas = document.createElement('canvas');
var value = 'mozPrintCallback' in canvas;
let canvas = document.createElement('canvas');
let value = 'mozPrintCallback' in canvas;
return shadow(this, 'supportsPrinting', value);
},