【发布时间】:2018-03-27 19:01:03
【问题描述】:
我正在使用PhantomJS 打印一个网页,其中包括文本和图表等多个元素(在 ChartJS 中)。文本看起来不错,但图表和图像看起来嘈杂且像素化。见:
注意图表边框是如何像素化的。这一定是 PhantomJS 光栅化问题,但没有找到任何设置来提高生成的 PDF 或光栅化过程的质量。
我试过了:
- 使用
page.dpi = 200;增加 DPI。好像没什么效果。 - 使用
page.property('dpi', 200);增加 DPI。一样,没有效果。 - 像这样增加视口大小
page.property('viewportSize', { width: 1920, height: 1080 });。增加屏幕尺寸,但质量保持不变。
这是我当前的脚本:
const phantom = require('phantom');
let url = "http://localhost:3000/";
phantom.create().then(function(ph) {
ph.createPage().then(function(page) {
page.property('viewportSize', { width: 1920, height: 1080 });
page.property('dpi', 200); //No effect?
page.dpi = 200; //No effect?
page.property('paperSize', { format: 'Letter', orientation: 'portrait' });
//page.property('zoomFactor', 3.5); //Works erratically
page.open(url).then(function(status) {
setTimeout(function () {
page.render("output-" + Date.now() + ".pdf", { format: "pdf" }).then(function() {
console.log('Page Rendered');
ph.exit();
});
}, 3000); //Change timeout as required to allow sufficient time
});
});
});
如何提高 PDF 光栅化/DPI 质量?
【问题讨论】:
标签: charts printing phantomjs chart.js dpi