-3

Possible Duplicate:
Capturing webpage as image in c#, ensuring javascript rendered elements are visible

I am trying on a project to allow the web page to be printed when clicked on a print button, and change the webpage that I am going to print into an image so that I could try watermark. Thanks.

Community
  • 1
  • 1
user1185370
  • 1
  • 1
  • 1
  • 5
    You should probably hire a .NET developer if you need help ASAP. Stack Overflow is not a good place for such kind of questions. If you expect to get help here you should show what you have tried so far and what difficulties have you encountered. – Darin Dimitrov Feb 02 '12 at 14:48
  • 2
    You are aware that you can't stop the user from printing your site with Ctrl+P.. Why not just add a background image that looks like a water mark on the page when the user prints. This can be done with the media setting in CSS http://www.w3.org/TR/CSS2/media.html – f2lollpll Feb 02 '12 at 14:49
  • There is a javascript library thats render the full html page to an image, maybe after this you can add your watermark. Check it out here http://stackoverflow.com/a/6789627/159270 Of cource this is not working with out javscript Here is a direct working page http://html2canvas.hertzen.com/tests/templates/artificial/index.html click to see the image, click again to see the html – Aristos Feb 02 '12 at 15:04

1 Answers1

1

In your ASPX page, put the following:

<input type="button" onclick="window.print();" value="Print" id="btnPrint" />

That creates a button that prints the webpage when you click it. Then, in your <head>, add the following:

<link rel="stylesheet" href="print.css" type="text/css" media="print" />

That will apply the print.css file only when printing. Create a file called print.css and add the following content:

body
{
    background-image: url('watermark.jpg') no-repeat center;
}
#btnPrint
{
    display: none;
}

Obviously, change watermark.jpg to be the name of the file you want to use as a watermark in the background.

IN SUM: You have created a print button and have assured that when your webpage is printed, it will use watermark.jpg as its background.

UPDATE:

As noted below, backgrounds do not print by default. The user would have to change their browser's print settings. So you should find a different way to show your watermark using text or an <img> element. The above code still shows you how to apply CSS only when printing.

Devin Burke
  • 13,642
  • 12
  • 55
  • 82