Last active
March 15, 2017 11:17
-
-
Save Maes95/9fcf84a725fcafba05ecd0857518a859 to your computer and use it in GitHub Desktop.
Simple export HTML element to PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function exportToPDF(title, id, css){ | |
setTimeout(function () { | |
var printWindow = window.open("", "", "width=1000, height=800"); | |
printWindow.document.write('<html><head><title>' | |
+title | |
+'</title>' | |
+css | |
+'</head><body onload="window.print()">' | |
+ document.getElementById(id).innerHTML | |
+ '</body></html>'); | |
printWindow.document.close(); | |
}, 1000); | |
} | |
var css = "<link href='https://rawgit.com/Semantic-Org/Semantic-UI/next/dist/semantic.css' rel='stylesheet'></link>"; | |
exportToPDF("MyTitle", "myDiv", css); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<div id="myDiv"> | |
<div class="ui button">Click me</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment