why there is a White space on the top on html2canvas?
GitHub Issue
You should check the document scroll, i face the same issue when page scroll is active or when page is scrolled down.
Try adding
{
scrollX: 0,
scrollY: -window.scrollY
}
to the html2canvas options
try adding this to your style css
*{
margin:0;
padding:0;
}
Also try to clear your browser cache, this would be the problem in most cases. If that doesn't work try to remove all your css styles and add them back one by one to see when and how it is being caused.
Following code worked for me
html2canvas(element , {
scrollX: -window.scrollX,
scrollY: -window.scrollY,
windowWidth: document.documentElement.offsetWidth,
windowHeight: document.documentElement.offsetHeight
})
I had a similar issue and through some trials I realised that by scrolling to the top of the page before generating the pdf solved it.
So I added this line to scroll to the top of the page before generating the pdf and it worked:
window.scrollTo(0,0);