I have a 650px X 1000px photo on a website page. There is a button below the photo.
How can I print the photo only except the full page. I want to save it as PDF or print only the image. Not save as image.
Open new window using window.open.
Write to it the img tag.
Once the image was loaded, print the document using
window.print().
Close the window using window.close()
You can do this with code like this:
Script
function printImg(url) {
var win = window.open('');
win.document.write('<img src="' + url + '" onload="window.print();window.close()" />');
win.focus();
}
Index.html
<img src="http://i.stack.imgur.com/hCYTd.jpg" />
<button onclick="printImg('http://i.stack.imgur.com/hCYTd.jpg')">Print</button>