打印网页带有水印 [英] Print a webpage with a watermark
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/7803201/capturing-webpage-as-image-in-c-ensuring-javascript-rendered-elements-are-visi\">Capturing网页在C#中的形象,确保JavaScript的渲染的元素是可见的
我想一个项目,允许当打印按钮点击要打印的网页,并更改我要打印成图像,这样我可以尝试水印的网页。谢谢你。
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.
推荐答案
在您的ASPX页面,把下面的:
In your ASPX page, put the following:
<input type="button" onclick="window.print();" value="Print" id="btnPrint" />
这将创建一个按钮,当你点击它,打印的网页。然后,在你的&LT; HEAD&GT;
,添加以下内容:
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" />
这将适用 print.css
文件的只有的打印时。创建一个名为print.css文件,并添加以下内容:
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;
}
显然,改变 watermark.jpg
来是你想要在后台水印使用的文件名。
Obviously, change watermark.jpg
to be the name of the file you want to use as a watermark in the background.
总之:您已经创建了一个打印按钮,并保证打印网页时,会使用 watermark.jpg
作为其背景。
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.
更新:
如下所述,背景默认不打印。用户将不得不改变他们的浏览器的打印设置。所以,你应该找到一个不同的方式来显示你的水印文字使用或者&LT; IMG&GT;
元素。以上code仍然显示打印时如何只适用CSS。
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.
这篇关于打印网页带有水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!