Subscribe to Youtube channel

Javascript print() method not printing Images ? then no problem i have a solution

If you are using window.Print() method of javascript to print the page but it prints only letters and does not print images of the page then use following solution for this problem

  • firstly try to use absolute url path in images src attribute like http://something.com/imger.jpg then it will be render correctly

  • secondly copy and paste below code in script tag 

function printContent(id){
var str=document.getElementById(id).innerHTML
newwin=window.open('','printwin','left=0,top=0,width=1,height=1,menubar=no')
newwin.document.write('<HTML>\n<HEAD>\n')
newwin.document.write('\n')
newwin.document.write('<script>\n')
newwin.document.write('function chkstate(){\n')
newwin.document.write('if(document.readyState=="complete"){\n')
newwin.document.write('window.close()\n')
newwin.document.write('}\n')
newwin.document.write('else{\n')
newwin.document.write('setTimeout("chkstate()",2000)\n')
newwin.document.write('}\n')
newwin.document.write('}\n')
newwin.document.write('function print_win(){\n')
newwin.document.write('window.print();\n')
newwin.document.write('chkstate();\n')
newwin.document.write('}\n')
newwin.document.write('<\/script>\n')
newwin.document.write('</HEAD>\n')
newwin.document.write('<BODY onload="print_win()">\n')
newwin.document.write(str)
newwin.document.write('</BODY>\n')
newwin.document.write('</HTML>\n')
newwin.document.close()
}

Call the above function in your buttons onclick event and send the div id to print

you will see in the print output text + images

Happy Coding!!!!!!!!!!!!!!:) 

Comments

Popular posts from this blog

Root your Gingerbread 2.3.4 android Mobile Phone

Restore the lost focus of Auto post back controls in asp.net update Panel control

Disable backspace key using Jquery

Implement Logging in CSV file using Nlog in .net core MVC application- part 2

Implement Nlog in .Net core MVC application part 1

Angular User Session Timeout example step by step

Devexpress Datebox date formatting in angular 6 with example

How to Import CSV File and bind csv file data to gridview in asp.net using c#

Add Comma automatically while entering amounts in textbox using Javascript