2013-04-23 191 views
0

我試圖打印白色文本黑色背景圖像,但是當我們啓用了「打印背景(顏色&圖片)它是唯一的工作。有沒有辦法通過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?了,但我無法找到解決方案。

誰能幫我解決這問題。

非常感謝 安娜

+0

IM不知道如果我明白你的問題,但是這有什麼錯設置'顏色:白色;背景顏色:黑色;'在CSS? – brendosthoughts 2013-04-23 05:49:41

+0

@brendan感謝您的評論,我也嘗試過。但仍然只將其打印爲黑色文本。 – 2013-04-23 06:02:43

回答

1

一種解決方法:在運行中生成的圖像。圖像生成在服務器上相當簡單,而且相對便宜。想驗證碼,但與你的顏色,字體,文本選擇等等等等

應該不會太大,即使從動態文本生成的挑戰。動畫會更難,但可能是可行的,如果你打印它,反正!

0

號網站不能改變瀏覽器設置。

這將是重大的安全漏洞,如果網站上的JavaScript可能會在瀏覽器更改用戶的喜好。

試想一下,如果網站可以使瀏覽器彈出窗口。

0

我按照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(); 
     } 

謝謝大家的時間,並幫助

非常感謝 安娜