【问题标题】:how to improve the print quality with pdf.js to print pdf document?如何使用 pdf.js 提高打印质量以打印 pdf 文档?
【发布时间】:2023-04-03 22:31:02
【问题描述】:

问题:

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

如何解决?

【问题讨论】:

标签: pdf.js


【解决方案1】:

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);

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

【讨论】:

    猜你喜欢
    • 2014-02-23
    • 2013-01-02
    • 1970-01-01
    • 2017-09-02
    • 2016-10-09
    • 2016-05-15
    • 2023-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多