createImage(){
let _this = this;
window.pageYoffset = 0;
document.documentElement.scrollTop = 0;
document.body.scrollTop = 0;'
let canvas = document.createElement("canvas");
let context = canvas.getContext("2d");
let _articleHtml = document.getElementById('imageTofile');
let _w = _articleHtml.clientWidth;
let _h = _articleHtml.clientHeight;
let scale = 3;
canvas.width = _w * scale;
canvas.height = _h * scale;
context.scale(scale, scale);
let opts = {
scale: 1,
width: _w,
height: _h,
canvas: canvas,
useCORS: true
};
(window.html2canvas || html2canvas)(_articleHtml, opts).then(canvas => {
_this.createPdfAll(canvas, scale);
});
},
createPdfAll (canvas, scale) {
let contentWidth = canvas.width / scale
let contentHeight = canvas.height / scale
let pdf = new jsPDF('', 'pt', [contentWidth, contentHeight+50])
let pageData = canvas.toDataURL('image/jpeg', 1.0);
pdf.addImage(pageData, 'JPEG', 0, 0, contentWidth, contentHeight)
let filename = 'question.pdf' ;
let datauri = pdf.output('dataurlstring');
let file = this.dataURLtoFile(datauri,filename);
this.uploadImg(file)
},
dataURLtoFile(dataurl, filename) {
var arr = dataurl.split(',');
var mime = arr[0].match(/:(.*?);/)[1];
var bstr = atob(arr[1]);
var n = bstr.length;
var u8arr = new Uint8Array(n);
while(n--){undefined
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, {type:mime});
},
|