Skip to content

Instantly share code, notes, and snippets.

@fredgdaley2
Created October 31, 2019 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredgdaley2/2c89631157304fb1e2a32c856791b490 to your computer and use it in GitHub Desktop.
Save fredgdaley2/2c89631157304fb1e2a32c856791b490 to your computer and use it in GitHub Desktop.
Print html to pdf
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.redhead {
color: red;
}
</style>
</head>
<body>
<div id="content">
<h1 class="redhead">Hello World</h1>
<p>this is a PDF</p>
<input type="radio" name="gender" value="male"> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other" checked> Other
</div>
<script>
var win = window.open("", "Title", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=200,top=" + (screen.height - 400) + ",left=" + (screen.width - 840));
win.document.head.innerHTML = document.head.innerHTML;
win.document.title = "John Smith Survey";
win.document.body.innerHTML = document.body.innerHTML;
win.print();
win.close();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment