【发布时间】:2016-01-21 23:08:56
【问题描述】:
我们在 jsPDF 和 HTML2canvas 的帮助下创建 pdf。但是图像分辨率有点高。
有没有办法用 jquery、javascript、jsPDF 和 html2canvas 获取低分辨率图像
function addElement(element, doc, opt, newPage, callback) {
var thiscreen = element;
//Get the original background color.
var originalBGColor = thiscreen.style.backgroundColor;
//Change the background color of the element to desired color.
if (opt.bgColor)
thiscreen.style.backgroundColor = opt.bgColor;
var options = options || {};
options.elements = [thiscreen];
//Increment the in-progress counter.
counter++;
console.log('adding' + counter);
console.log(element);
//The complete callback method.
options.complete = setTimeout(function(images) {
//Decrement the in-progress counter since the image is successfully generated..
counter--;
console.log('complete' + counter);
console.log(element);
var queue = html2canvas.Parse(thiscreen, images, options),
canvas = html2canvas.Renderer(queue, options);
//Reset the background color.
thiscreen.style.backgroundColor = originalBGColor;
//Add the generated image to PDF document.
doc.addImage(canvas.toDataURL(), 'png', opt.x, opt.y, opt.width, opt.height);
//Call the callback method if any
if (callback) {
callback();
}
}, 500);
//Conver the html to PNG using html2canvas util.
html2canvas.Preload(thiscreen, options);
}
【问题讨论】:
标签: javascript jquery jspdf html2canvas