I just tried your code in a working JSBin here http://jsbin.com/catubuwa/1/edit?html,js,output on Windows 8.1 using Chrome and it seems to work just fine as you expect when printing to a .pdf file. However, I seem to notice that there might be a race condition and load timing issue. Maybe in your case the page is loading and being prepped for print before the page or image has loaded fully?
If that is what's happening I've added a basic .ready() for your myWindow to then print:. But if you notice I've taken out the close. This also seems to help as well. The reason being is that the print function is actually being called on this window and therefor is the print dialog. This will vary based on browser but the close also seemed to have an impact on the printing as well.
jQuery('#print').on("click", function(){
var mywindow = window.open('', 'my div', 'height=400,width=600');
mywindow.document.write('<html><head><title>Title</title>');
mywindow.document.write('</head><body >');
mywindow.document.write('<img id="myImage" src="https://www.google.pl/images/srpr/logo11w.png" alt="logo"/>');
mywindow.document.write('</body></html>');
$(mywindow).ready(function() {
// Call Later In Stack - really should be onload events or base64 images inline
setTimeout(
function(){
mywindow.print();
},(1000));
});
});
Maybe staging the process might help ensure that everything is ready to be printed when the new window is opened and constructed.
Working Copy:
http://jsbin.com/catubuwa/1/edit?html,js,output
References: