3

Hi,

My application is in asp.net MVC3 coded in C#.Net, I have a certain view with the requirement to print the complete Html of a particular div in that view.

Suppose

<div id="Printable_Div" >
    <div>
    <img id="First_Image" src="Source of my Image">
    </div>
    <table>My table data
    </table>
</div>

Following are the things i tried

  var w = window.open();
  w.document.write($("#Printable_Div").html());
  w.print();
  w.close();

Also i have tried using the jquery printElement.js

$("#Printable_Div").printElement();

And Also window.print(); I have also tried setting the Image as the background of the

<div style="background-image:My Image"></div>

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 image in the print as well. The image tag is shown in the print preview but not the image.

Updated

Also i have tried printing the entire page by using the below code.

<div id="Printable_Div" onclick="Print_Function()">
</div>

Javascript function

    <script type="text/javascript">
        function Print_Function() {
        window.print();
        }

    </script>
Sam M
  • 1,077
  • 2
  • 20
  • 42
  • Would these SO answers help? http://stackoverflow.com/questions/2255291/print-the-contents-of-a-div http://stackoverflow.com/questions/7791158/print-div-contents-in-javascript http://stackoverflow.com/questions/468881/print-div-id-printarea-div-only – philip May 09 '13 at 05:19
  • @trythisinstead i have gone thru all the links given in the comment, unfortunately none helped me solving my issue with the image. Im able to play around well with printing the Html in different ways, but in any way i tried none helping me in showing and printing the images available in my Div – Sam M May 09 '13 at 05:53

1 Answers1

-1

Try This way,

<button onclick="window.print();printDiv(document.getElementById('Printable_Div'));">Save as PNG Image</button>

R.Malla
  • 1
  • 2