Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
134
rated 0 times [  138] [ 4]  / answers: 1 / hits: 71303  / 9 Years ago, mon, march 23, 2015, 12:00:00

Im working at a simple javascript.
im using the jsPDF lib but the script load a blank pdf.



this is the code :



    <html xmlns=http://www.w3.org/1999/xhtml xml:lang=en lang=en>

<head>
<title>fromHTML EX</title>
<meta http-equiv=content-type content=text/html;charset=utf-8 />
<meta name=generator content=Geany 1.22 />

<script type=text/javascript src=/root/utils/jquery-1.11.2.min.js></script>
<script type=text/javascript src=/root/utils/jsPDF-master1/jspdf.plugin.standard_fonts_metrics.js></script>
<script type=text/javascript src=/root/utils/jsPDF-master1/jspdf.plugin.split_text_to_size.js></script>

<script type=text/javascript src=/root/utils/jsPDF-master1/js/basic.js></script>
<script type=text/javascript src=/root/utils/jsPDF-master1/jspdf.js></script>
<script type=text/javascript src=/root/utils/jsPDF-master1/jspdf.plugin.from_html.js></script>

<script type=text/javascript>
function PDF1(){
var doc = new jsPDF();
var elementHandler = {
'#ignorePDF': function (element, renderer) {
return true;
}
};
var source = window.document.getElementsByTagName(body)[0];
doc.fromHTML(
source,
15,
15,
{
'width': 180,'elementHandlers': elementHandler
});

doc.output(datauri);
}

PDF1()
</script>

</head>

<body>
ASDSADASDASDSA
<div>
<p id=ignorePDF>don't print this to pdf</p>

<p><font size=3 color=red>print this to pdf</font></p>
</div>




</body>


</html>


i have tryied to put the calling function at the bottom of the page but it still don't work.
Can someone help me?


More From » jspdf

 Answers
10

Since you are using jQuery try:



$( document ).ready(function() {
//console.log( ready! );
PDF1();
});


Also Note: You could use (not required):



var source = $(body)[0];


Code page used to test



<html xmlns=http://www.w3.org/1999/xhtml xml:lang=en lang=en>
<head>
<title>fromHTML EX</title>
<meta http-equiv=content-type content=text/html;charset=utf-8 />
<meta name=generator content=Geany 1.22 />

<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js></script>
<script src=https://parall.ax/parallax/js/jspdf.js></script>

<script type=text/javascript>
function PDF1(){
var doc = new jsPDF();
var elementHandler = {
'#ignorePDF': function (element, renderer) {
return true;
}
};
var source = window.document.getElementsByTagName(body)[0];
doc.fromHTML(
source,
15,
15,
{
'width': 180,'elementHandlers': elementHandler
});

doc.output(datauri);
}

$( document ).ready(function() {
//console.log( ready! );
PDF1();
});
</script>

</head>

<body>
ASDSADASDASDSA
<div>
<p id=ignorePDF>don't print this to pdf</p>

<p><font size=3 color=red>print this to pdf</font></p>
</div>




</body>
</html>

[#67340] Friday, March 20, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristinadomoniquel

Total Points: 320
Total Questions: 94
Total Answers: 94

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
cristinadomoniquel questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Mon, Aug 17, 20, 00:00, 4 Years ago
;