How to print a tiff image using javascript?
I am using html button to print tiff image. When I click the Print button, a new window opens. Below is the code
var printThis = "<img src='image.tiff' width='100%'>"
win = window.open();
self.focus();
win.document.open();
win.document.write('<html><head><style>body { font-family: Verdana; font-size: 10pt; }</style></head><body>');
win.document.html(printThis);
win.document.write('</body></html>');
win.document.close();
win.print();
win.close();
this code doesn't work as expected as it doesn't display image.tiff.
If I replace "printThis" with this code
var printThis = '<embed id="pre" access="4" src="' + imgName + '" type="image/tiff" width="100%" />';
An image will appear, but if I print the page, the image will not be printed.
I am using AlternaTIFF to display tiff images. please suggest me a solution for this. I am not getting an answer to this.
source to share
Why are you using again .write
, then .html
.write
? Could you try:
var printThis = "image.tiff"
win = window.open();
self.focus();
win.document.open();
win.document.write('<html><head><style>body { font-family: Verdana; font-size: 10pt; }</style></head><body><img src="' + printThis + '" width="100%"></body></html>');
win.document.close();
win.print();
win.close();
Also, I tried and had an issue with the print popup getting stuck (in FF) making the browser continuous while still blocking the image from being printed. I was able to click a button stop
in the browser to clear the popup and then everything printed ok. So you can look at the print section of your script.
source to share