gpt4 book ai didi

pdf.js - 如何使用 pdf.js 提高打印质量以打印 pdf 文档?

转载 作者:行者123 更新时间:2023-12-04 12:46:27 25 4
gpt4 key购买 nike

问题:

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

如何解决?

最佳答案

PDF.js 将 PDF 呈现到 HTML Canvas ,然后将呈现的图像发送到打印机。要提高发送到打印机的图像质量,您需要提高图像的 DPI 或分辨率。

关于这个问题已经提出了几个错误:

  • https://github.com/mozilla/pdf.js/issues/7094
  • https://github.com/mozilla/pdf.js/issues/7041
  • https://github.com/mozilla/pdf.js/issues/6498
  • https://github.com/mozilla/pdf.js/issues/6241

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

    查看器.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);

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

    关于pdf.js - 如何使用 pdf.js 提高打印质量以打印 pdf 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36330102/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com