I'm using jsPDF and html2canvas to convert a div
to pdf:
<a onclick="makePdf()">PDF</a>
<div id="divToPdf">Some content here</div>
However I don't want my div
displayed on the screen. I tried using hidden
property to hide the div
:
<a onclick="makePdf()">PDF</a>
<div id="divToPdf" hidden>Some content here</div>
The problem is that the hidden
property results in a blank pdf document. How do I go about hiding the div
without this problem?
To hide an HTML tag; add this attribute tag data-html2canvas-ignore="true"
instead of the hidden
.
So with Mario Alexandro Santini's suggestion in the comments, I was able to solve the problem. I used jquery to unhide the div
in my makePdf()
function then hide it again after jsPDF and html2canvas had done their "magic":
function makePdf() {
$("#divToPdf").attr("hidden", false);
...
$("#divToPdf").attr("hidden", true);
}
Thanks guys!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With