0
I am trying to generate a PDF with js
using html2canvas
and jsPDF
. When the content is being viewed, everything works 100%, but I need this content to be hidden. I’ve tried:
- display: none;
- visibility: hidden;
- Position: absolute;
Among other things. It always returns me this error when I try to generate pdf with "hidden" content on the page.
jspdf.debug.js:2571 Uncaught Error: Supplied data is not a JPEG
Below is the code used:
<div id="conteudo-pdf">
Conteúdo
</div>
<script type="text/javascript">
var doc = new jsPDF();
$('#btGerarPDF').click(function () {
doc.addHTML($("#conteudo-pdf"), function(){
doc.save('arquivo.pdf');
});
});
</script>
You need to display the page as it is made a
print
of the screen and placed in thePDF
– Rafael Augusto
Mount a "printable" version of the page without the content you want to hide.
– Oralista de Sistemas
Change
.addHTML
for.fromHTML
and lower the library most recent:var html = $("#conteudo-pdf").contents();
– Ivan Ferrer