问题:
当我使用pdf.js打印PDF文档时,纸上的文字并不像印刷PDF那样直接。
如何解决?
答案 0 :(得分: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);
要提高质量,请将视口因子增加到更高的值。