【发布时间】:2023-04-03 22:31:02
【问题描述】:
问题:
当我使用pdf.js打印PDF文档时,纸上的文字不像直接打印PDF那样清晰。
如何解决?
【问题讨论】:
-
我看到过类似的问题,stackoverflow.com/questions/21719393/…,但还没有解决方案。
标签: pdf.js
问题:
当我使用pdf.js打印PDF文档时,纸上的文字不像直接打印PDF那样清晰。
如何解决?
【问题讨论】:
标签: pdf.js
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);
要提高质量,请将视口因子增加到更高的值。
【讨论】: