2016-01-21 246 views
0

我們在jsPDF和HTML2canvas的幫助下創建PDF。但圖像分辨率有點高。低分辨率圖像jspdf和Html2Canvas

有沒有什麼辦法讓使用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); 
    } 

回答