Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to print Html page with image using Javascript
    primarykey
    data
    text
    <p><strong>Hi,</strong></p> <p>My application is in asp.net <strong>MVC3</strong> coded in <strong>C#.Net</strong>, I have a certain view with the requirement to print the complete Html of a particular div in that view.</p> <p>Suppose </p> <pre><code>&lt;div id="Printable_Div" &gt; &lt;div&gt; &lt;img id="First_Image" src="Source of my Image"&gt; &lt;/div&gt; &lt;table&gt;My table data &lt;/table&gt; &lt;/div&gt; </code></pre> <p><strong>Following are the things i tried</strong> </p> <pre><code> var w = window.open(); w.document.write($("#Printable_Div").html()); w.print(); w.close(); </code></pre> <p>Also i have tried using the jquery printElement.js</p> <pre><code>$("#Printable_Div").printElement(); </code></pre> <p>And Also window.print(); I have also tried setting the Image as the background of the</p> <pre><code>&lt;div style="background-image:My Image"&gt;&lt;/div&gt; </code></pre> <p>There is not any issue in printing the Html page, but the issue is, image is not getting displayed in all the three methods tried above. I want to print the entire HTML that is available in the Div with the ID=Printable_Div Is there any way to display the <strong>image</strong> in the print as well. The image tag is shown in the <strong>print preview</strong> but not the image.</p> <p><strong>Updated</strong></p> <p>Also i have tried printing the entire page by using the below code.</p> <pre><code>&lt;div id="Printable_Div" onclick="Print_Function()"&gt; &lt;/div&gt; </code></pre> <p><strong>Javascript function</strong></p> <pre><code> &lt;script type="text/javascript"&gt; function Print_Function() { window.print(); } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload