<a href="_javascript:window.print()">
<img class="noPrint" src="Images/Print_icon.png" border="0"></a>
This is the only code i am using to implement print function. It generates a print dialog box. And to make the page print friendly, I have used stylesheets and hid the div's that I dont want in the print page.
I now need to generate a print preview of that page. Any suggestions?
Thanks
Basically there is no functionality available until now but you can achieve by creating a copy of same html file with name
print.htm
with the Print css and open this file on button Print Preview click as a popup page and render it, This will preview the page :I really don't see this as practical. Your web page has no knowledge of font size (zoom level), page margins, orientation or anything else you'd need to know to construct a print preview image.
In addition, it's possible for a page to reference images and other content from other sites. How will your code know what is needed here?
Fortunately, the browsers I use (IE and Chrome) provide print preview, so you'd get it for free anyway. But if you're trying to implement print preview manually, I just don't see that as a practical goal.
One way is to use the mediaType print in your css. This css will only be applied when you open you page in print mode. Add following class in your css file:
Another way is by using pure javascript. there are bunch of articles on internet for this:
If you are having a common template for printer friendly pages. I would suggest you to create a seperate page altogether for print version and when user clicks on link navigate it to your new printer friendly page. I would recommed this approach as this is foolproof and you have complete control over it, rest of approaches have some pitfalls.