自己生成的页面,保存为图片,并下载word
// 下载word$(document).on("click",".wordbtn",function(){var images = $('.swiper-wrapper .swiper-slide');var imagesData = [];var promises = [];images.each(function() {var promise = html2canvas(this).then(function(canvas) {var imgData = canvas.toDataURL('image/png');imagesData.push(imgData);});promises.push(promise);});Promise.all(promises).then(function() {var content = `<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'><head><meta charset='utf-8'></head><body>`;imagesData.forEach(function(data) {content += `<img src='${data}'><br><br>`;});content += `<p>${$('.text1').html()}</p><p>${$('.text2').html()}</p></body></html>`;var blob = new Blob(['\ufeff', content], {type: 'application/msword'});saveAs(blob, 'document.doc');});});