如何用pdf.js提高打印质量来打印pdf文档?

问题描述 投票:7回答:1

问题:

当我使用pdf.js打印PDF文档时,纸上的文字不像印刷PDF那样直接。

怎么解决?

pdf.js
1个回答
2
投票

PDF.js将PDF呈现为HTML画布,然后将渲染的图像发送到打印机。要提高发送到打印机的图像质量,需要增加图像的DPI或分辨率。

关于这个问题已经出现了一些错误:

这是Pull Request。要应用补丁,请找到beforePrint函数并对viewer.js进行以下更改。

viewer.js

  // increase to improve quality
  var viewport = pdfPage.getViewport(4);
  // Use the same hack we use for high dpi displays for printing to get
  // better output until bug 811002 is fixed in FF.
  var DPI = 72; // increase to improve quality
  var PRINT_OUTPUT_SCALE = DPI/72; 
  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 rendered size of the canvas, relative to the size of canvasWrapper.
  canvas.style.width = '100%';

  CustomStyle.setProp('transform' , canvas, 'scale(1,1)');
  CustomStyle.setProp('transformOrigin' , canvas, '0% 0%');

  var canvasWrapper = document.createElement('div');
  canvasWrapper.style.width = '100%';
  canvasWrapper.style.height = '100%';

  canvasWrapper.appendChild(canvas);
  printContainer.appendChild(canvasWrapper);

要提高质量,请将视口因子增加到更高的值。

© www.soinside.com 2019 - 2024. All rights reserved.