/    Sign up×
Community /Pin to ProfileBookmark

Export / Convert Website to PDF

I would like to know how can I export a HTML or website document to PDF.

The idea would be to have a buttom to click and convert the document.

I tried this but I get and error in var conv = new ActiveXObject(“pdfServMachine.converter”); –> “Element ActiveXObject is not defined”

[CODE]
<!DOCTYPE html>
<html>
<head>
<script type=”text/javascript”>

function init() {
var conv = new ActiveXObject(“pdfServMachine.converter”);
conv.convert(“http://www.google.com”, “c:\google.pdf”, false);
WScript.Echo(“finished conversion”);
}
</script>
</head>
<body>
Here is content of the site
<div id=”init”>
<button onclick=”init()”>Export to PDF</button>
</body>
</html>[/CODE]

Also tried this but not sure how to use the jspdf. Get an error in line: printDoc.fromHTML($(‘#pdf’).get(0), 10, 10, {‘width’: 180}); –> “$ is not defined”

[CODE]<!DOCTYPE html>
<html>
<head>
<title>html2canvas example</title>
<script type=”text/javascript” src=”js/jspdf.js”></script>
<script type=”text/javascript” src=”js/plugins/addimage.js”></script>
<script type=”text/javascript” src=”js/plugins/standard_fonts_metrics.js”></script>
<script type=”text/javascript” src=”js/plugins/split_text_to_size.js”></script>
<script type=”text/javascript” src=”js/plugins/from_html.js”></script>
<script type=”text/javascript”>

function printPDF() {
var printDoc = new jsPDF();
printDoc.fromHTML($(‘#pdf’).get(0), 10, 10, {‘width’: 180});
printDoc.autoPrint();
printDoc.output(“dataurlnewwindow”); // this opens a new popup, after this the PDF opens the print window view but there are browser inconsistencies with how

this is handled
}

var doc = new jsPDF();
var specialElementHandlers = {
‘#editor’: function (element, renderer) {
return true;
}
};

</script>
</head>
<body>
Content of the Site

<button onclick=”printPDF()”>Export to PDF</button>
</body>
</html>[/CODE]

THANK YOU SO MUCH

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @samuvk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...