I am using react as a frontend application, I want to export a portion of react component as pdf file using jsPdf.
const handleDownload = () => {
const content = document.getElementById('download-content');
const doc = new jsPDF();
doc.html(content);
doc.save("a4.pdf");
}
React return component is:
return (
<body>
<header id='download-content'>
<div>l kldfjlkasjfld asjflkajf ljfasd'flksdasjf lsdasjfsadf</div>
<div>l kldfjlkasjfld asjflkajf ljfasd'flksdasjf lsdasjfsadf</div>
<div>l kldfjlkasjfld asjflkajf ljfasd'flksdasjf lsdasjfsadf</div>
<div>l kldfjlkasjfld asjflkajf ljfasd'flksdasjf lsdasjfsadf</div>
<div>l kldfjlkasjfld asjflkajf ljfasd'flksdasjf lsdasjfsadf</div>
<div>l kldfjlkasjfld asjflkajf ljfasd'flksdasjf lsdasjfsadf</div>
</header>
<footer>
<button onClick={handleDownload}>Download</button>
</footer>
</body>
)
After click on Download
button I want a pdf file which consists header
tag data with style. But here I got blank pdf with this function handleDownload
.
I don't want to use canvas to generate image and then make pdf.. If I use canvas then, when page size minimize the pdf will change.
How can I get exact html generated page as pdf?
div
tag not show. It's cuttoff half content. How can I got properly all things. Also, when I do responsive the content got in pdf not remain same. It also become like response.. but I want it as standard as full page view – Bowyer