Last active
June 6, 2016 21:43
-
-
Save kodie/3f016e1a6f325b0d60f6 to your computer and use it in GitHub Desktop.
Print just an image from a page.
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 printImage(image, title) { | |
var winContent = "<html><head><title>" + title + "</title><script>function step1(){\n" + | |
"setTimeout('step2()', 10);}\n" + | |
"function step2(){window.print();window.close()}\n" + | |
"</scri" + "pt></head><body onload='step1()'>\n" + | |
"<img src='" + image + "' /></body></html>"; | |
var win = window.open('about:blank', '_new'); | |
win.document.open(); | |
win.document.write(winContent); | |
win.document.close(); | |
} | |
printImage('path/to/image.png', 'Title for top of page'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment