如何打印白色文本黑色背景图像
问题描述:
我试图打印白色文本黑色背景图像,但是当我们启用了“打印背景(颜色&图片)它是唯一的工作。有没有办法通过jQuery来启用此或其他变通来解决这个问题。这是我的示例代码。如何打印白色文本黑色背景图像
<script type="text/javascript">
$(function() {
var print = $('.printButton');
print.bind('mousedown', function() {
$('.FirstName').attr("style", "background: transparent !important;color:#FFEFD5;-webkit-print-color-adjust: exact;");
window.print();
});
});
</script>
<div >
<div >
<asp:Image runat="server" ID="imgIO" ImageUrl="/css/Images/Img-Black.jpg" />
</div>
<div class="FirstName">Hello</div>
</div>
<div>
<div class="printButton">
<asp:Button runat="server" ID="Button2" />
</div>
</div>
.FirstName {
color: #eee;
font-size: 11px;
font-weight: bold;
position: absolute;
top: 15px;
left: 72px;
}
.printButton {
margin: 0 -3px 0 0;
float: right;
font-family: Arial;
direction: ltr;
}
我验证了这个链接Can I force text to print as white?了,但我无法找到解决方案。
谁能帮我解决这问题。
非常感谢 安娜
答
一种解决方法:在运行中生成的图像。图像生成在服务器上相当简单,而且相对便宜。想验证码,但与你的颜色,字体,文本选择等等等等
应该不会太大,即使从动态文本生成的挑战。动画会更难,但可能是可行的,如果你打印它,反正!
答
号网站不能改变浏览器设置。
这将是重大的安全漏洞,如果网站上的JavaScript可能会在浏览器更改用户的喜好。
试想一下,如果网站可以使浏览器弹出窗口。
答
我按照Nenotlep的建议得到了答案。这里是我的下面的代码来解决我的问题。
private void LoadBlackImage(string imageUrl, string firstName, string lastName, string Number, string Date)
{
Bitmap bitMapImage = new Bitmap(Server.MapPath(imageUrl));
Graphics graphicImage = Graphics.FromImage(bitMapImage);
SolidBrush drawBrush = new SolidBrush(Color.White);
HtmlGenericControl dynImage = new HtmlGenericControl("img");
dynImage.ID = "imgBlack";
dynImage.Attributes.Add("runat", "server");
//Smooth graphics is nice.
graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
//Write your text.
graphicImage.DrawString(firstName, new Font("Arial", 8, FontStyle.Regular), drawBrush, new Point(50, 70));
graphicImage.DrawString(lastName, new Font("Arial", 8, FontStyle.Regular), drawBrush, new Point(50, 85));
graphicImage.DrawString(Number, new Font("Arial", 8, FontStyle.Regular), drawBrush, new Point(50, 100));
graphicImage.DrawString(Date, new Font("Arial", 8, FontStyle.Regular), drawBrush, new Point(50, 115));
//Save the new image to the response output stream.
MemoryStream ms = new MemoryStream();
bitMapImage.Save(ms, ImageFormat.Jpeg);
var base64Data = Convert.ToBase64String(ms.ToArray());
//lblGiftCardRightIO.Src = "data:image/jpeg;base64," + base64Data;
dynImage.Attributes.Add("src", "data:image/jpeg;base64," + base64Data);
divControl.Controls.Add(dynImage);
//Clean house.
graphicImage.Dispose();
bitMapImage.Dispose();
}
谢谢大家的时间,并帮助
非常感谢 安娜
IM不知道如果我明白你的问题,但是这有什么错设置'颜色:白色;背景颜色:黑色;'在CSS? – brendosthoughts 2013-04-23 05:49:41
@brendan感谢您的评论,我也尝试过。但仍然只将其打印为黑色文本。 – 2013-04-23 06:02:43