Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

i have dynamically created table with string builder..

when i run this page background color is applied to 'th' but when print the page it doesnt print background color. But when i applied font color to 'th' then it prints font color after printing..

C#
StringBuilder strhtmlcontent = new StringBuilder();
strhtmlcontent.Append("<table id='mytable' align='Center' style='background-color:#' BORDER-COLLAPSE:collapse cellSpacing=0 rules=all border=1 width=100% ><th width=8% style='background-color:Lime;'>FirstName</th>");
strhtmlcontent.Append("</table>");
ttpContext.Current.Response.Write(strhtmlcontent);
HttpContext.Current.Response.Flush();


Thanks.

[edit]pre tag added - @amit[/edit]
Posted
Updated 21-Feb-12 0:47am
v4
Comments
AmitGajjar 21-Feb-12 6:41am    
is this the only two line of code you have ? in above code TABLE is not ended. it's not correct html format. so can you post your full code ?
Sergey Alexandrovich Kryukov 21-Feb-12 13:03pm    
Replacing background colors with transparent is the usual Web browser behavior for printing. It depends on the browser which may or may not have relevant options.
--SA

1 solution

There is a possibility to define separate CSS styles for media type print. Here[^]'s a little article. You should find plenty like this if you Googled.

But my personal experience is, most web browsers ignore properties like background color when they print a page. The truth is, 'ability to view web pages' being the prime objective of web browsers, most of them are not programmed smart enough to print everything they render.

A smart thing to do would be to design a separate printer friendly style. Where there are no floating bodies or no backgrounds, and minimal amount of colors used for texts (you need to use colors for images though), and the only the content of the page is displayed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900