问题
I use Html2Canvas and then jsPdf to export the image.
This is the function:
function exportPdf() {
content = $("#print");
var useWidth = content.prop('scrollWidth');
var useHeight = content.prop('scrollHeight');
debugger;
html2canvas((content), { width: useWidth, height: useHeight}).then(function (canvas) {
debugger;
var img = canvas.toDataURL("image/png");
var doc = new jsPDF({
unit:'px',
format:'a4'
});
debugger;
doc.addImage(img, 'JPEG', 0, 0);
doc.save('test.pdf');
});
}
I think is taking in consideration the viewport, is like doing a printscreen, of course whatever is below the scroll it doesn't take it into consideration.
Any ideas?
回答1:
Call
window.scrollTo(0,0)
Before calling html2canvas, its seems its a bug but the window needs to be at the top for html2canvas to capture the entire DOM passed to it
来源:https://stackoverflow.com/questions/40349075/html2canvas-image-is-getting-cut