[英]Low resolution Image jspdf and Html2Canvas
我們正在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);
}
可以使用任何工具降低圖像的分辨率,但使用jquery降低分辨率可能並不容易。 嘗試使用工具縮小圖像尺寸並參考。 http://blog.teamtreehouse.com/using-jquery-asynchronously-loading-image
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.