Skip to content

Instantly share code, notes, and snippets.

@MdKutubuddinSardar
Created March 5, 2018 14:10
Show Gist options
  • Save MdKutubuddinSardar/31e0909e67b3ab7bf3cf40c9f20d216c to your computer and use it in GitHub Desktop.
Save MdKutubuddinSardar/31e0909e67b3ab7bf3cf40c9f20d216c to your computer and use it in GitHub Desktop.
HTML-to-PDF with jQuery
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="https://docraptor.com/docraptor-1.0.0.js"></script>
<script>
var downloadPDF = function() {
DocRaptor.createAndDownloadDoc("YOUR_API_KEY_HERE", {
test: true, // test documents are free, but watermarked
type: "pdf",
document_content: document.querySelector('html').innerHTML, // use this page's HTML
// document_content: "<h1>Hello world!</h1>", // or supply HTML directly
// document_url: "http://example.com/your-page", // or use a URL
// javascript: true, // enable JavaScript processing
// prince_options: {
// media: "screen", // use screen styles instead of print styles
// }
})
}
</script>
<style>
@media print {
#pdf-button {
display: none;
}
}
</style>
</head>
<body>
<h1>Example!</h1>
<input id="pdf-button" type="button" value="Download PDF" onclick="downloadPDF()" />
</body>
</html>
@MdKutubuddinSardar
Copy link
Author

Converting HTML into PDF and XLS documents with jQuery is fast and painless with DocRaptor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment