admin管理员组文章数量:1277383
I have web page with containing data I want that when I click generate pdf button it should create pdf of that page. And Save Locally .
I have searched alot but I am getting script to only create pdf by entering data is there any other way
Below is the method which I tried but it is not suitable I want to create whole page into pdf file.
jspdf
I also tried another code but it also does not create the file
<script>
function generatePDF(){}
var conv = new ActiveXObject("pdfServMachine.converter");
conv.convert("", "c:\\google.pdf", false);
WScript.Echo("finished conversion");
}
</script>
<body onload="generatePDF()">
</body>
</html>
I have web page with containing data I want that when I click generate pdf button it should create pdf of that page. And Save Locally .
I have searched alot but I am getting script to only create pdf by entering data is there any other way
Below is the method which I tried but it is not suitable I want to create whole page into pdf file.
jspdf.
I also tried another code but it also does not create the file
<script>
function generatePDF(){}
var conv = new ActiveXObject("pdfServMachine.converter");
conv.convert("http://www.google.", "c:\\google.pdf", false);
WScript.Echo("finished conversion");
}
</script>
<body onload="generatePDF()">
</body>
</html>
Share
Improve this question
edited Nov 3, 2013 at 20:36
BenMorel
36.6k51 gold badges205 silver badges336 bronze badges
asked Nov 19, 2012 at 6:15
user1808433user1808433
3,4054 gold badges18 silver badges17 bronze badges
8
- stackoverflow./questions/1686280/… – Akhilraj N S Commented Nov 19, 2012 at 6:18
- if this is a direct copy from your code than you need to write the word function correctly – Eyal Alsheich Commented Nov 19, 2012 at 6:19
- @EyalAsheich yes i have made it write but nothing happens – user1808433 Commented Nov 19, 2012 at 6:21
- 2 Have you tried printing the page?? – Steve Robinson Commented Nov 19, 2012 at 6:22
- @AkhilrajNS the link you provides is fine can you help me overhere to add that code and where is the file saved – user1808433 Commented Nov 19, 2012 at 6:22
2 Answers
Reset to default 3You didn't declare the function correctly. It should be generatePDF(){
instead of generatePDF(){}
. Your }
should be at the end of the function only.
I am a bit late but let me tell you that, the code you are using is only patible with old versions of Microsoft browser(i.e) because it contains WScript & ActiveX Component.
Yes, you can generate it with jsPDF.js
. Just search this javascript file in google and download it locally then include it like shown below.
<script src="~/js/jspdf.js"></script>
<script>
var doc = new jsPDF('p', 'pt', 'letter');
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
$('#btn_Pdfprint').click(function () {
doc.fromHTML($('#myTabContent').html(), 25, 25, {
'width': 790,
'elementHandlers': specialElementHandlers
});
doc.save('mywebpagee.pdf');
window.location.reload();
});
</script>
本文标签: javascripthow to convert a web page into pdf by button click in html5Stack Overflow
版权声明:本文标题:javascript - how to convert a web page into pdf by button click in html5 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741242049a2364172.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论