admin管理员组文章数量:1349699
I am trying to export the webpage into pdf file when user click the button, but the below code is not working for me . can any one please help me where I went wrong. I am using jsPDF to export the web page into pdf.
<!DOCTYPE html>
<html lang="en">
<head>
<title>html2canvas example</title>
<script type="text/javascript" src="js/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="js/jspdf.js"></script>
<script type="text/javascript" src="libs/Deflate/adler32cs.js"></script>
<script type="text/javascript" src="libs/FileSaver.js/FileSaver.js"></script>
<script type="text/javascript" src="libs/Blob.js/BlobBuilder.js"></script>
<script type="text/javascript" src="jspdf.plugin.addimage.js"></script>
<script type="text/javascript" src="jspdf.plugin.standard_fonts_metrics.js"></script>
<script type="text/javascript" src="jspdf.plugin.split_text_to_size.js"></script>
<script type="text/javascript" src="jspdf.plugin.from_html.js"></script>
<script type="text/javascript" src="js/basic.js"></script>
<script type="text/javascript">
$(function ()
{
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
$('#cmd').click(function () {
doc.fromHTML($('#content').html(), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.save('sample-file.pdf');
});
});
</script>
</head>
<body id="target" >
<div id="content">
<h3>Hello, this is a H3 tag</h3>
<p>a pararaph</p>
</div>
<div id="editor"></div>
<button id="cmd">generate PDF</button>
</body>
</html>
I am trying to export the webpage into pdf file when user click the button, but the below code is not working for me . can any one please help me where I went wrong. I am using jsPDF to export the web page into pdf.
<!DOCTYPE html>
<html lang="en">
<head>
<title>html2canvas example</title>
<script type="text/javascript" src="js/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="js/jspdf.js"></script>
<script type="text/javascript" src="libs/Deflate/adler32cs.js"></script>
<script type="text/javascript" src="libs/FileSaver.js/FileSaver.js"></script>
<script type="text/javascript" src="libs/Blob.js/BlobBuilder.js"></script>
<script type="text/javascript" src="jspdf.plugin.addimage.js"></script>
<script type="text/javascript" src="jspdf.plugin.standard_fonts_metrics.js"></script>
<script type="text/javascript" src="jspdf.plugin.split_text_to_size.js"></script>
<script type="text/javascript" src="jspdf.plugin.from_html.js"></script>
<script type="text/javascript" src="js/basic.js"></script>
<script type="text/javascript">
$(function ()
{
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
$('#cmd').click(function () {
doc.fromHTML($('#content').html(), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.save('sample-file.pdf');
});
});
</script>
</head>
<body id="target" >
<div id="content">
<h3>Hello, this is a H3 tag</h3>
<p>a pararaph</p>
</div>
<div id="editor"></div>
<button id="cmd">generate PDF</button>
</body>
</html>
Share
Improve this question
edited Feb 1, 2016 at 8:53
Greg
3433 silver badges17 bronze badges
asked Nov 5, 2013 at 7:24
NavyahNavyah
1,68011 gold badges33 silver badges59 bronze badges
2
- I can see that this code es from the documentation, can you add the errors you are seeing in the JavaScript console – Jason Sperske Commented Nov 5, 2013 at 7:40
- possible duplicate of Export HTml page to PDF on user click using javascript – Kristof Feys Commented Nov 5, 2013 at 10:48
2 Answers
Reset to default 4There is an error in the script. Please try this code
<script>
$(document).ready(function (){
$('#cmd').click(function () {
var specialElementHandlers =
function (element,renderer) {
return true;
}
var doc = new jsPDF();
doc.fromHTML($('#content').html(), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.output('datauri');
});
});
</script>
The fromHTML function was replaced by html and you have to add html2canvas manually. Have a look at this link:
https://stackoverflow./a/78587984/14938811
本文标签: javascriptExporting web page into PDF using jsPDfStack Overflow
版权声明:本文标题:javascript - Exporting web page into PDF using jsPDf - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743842895a2548603.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论