Jump to content

white character turns gray in window.print()


GernotM

Recommended Posts

I've edited your example on window.print() as follows:<!DOCTYPE html><html><head><script>function printpage(){window.print();}</script></head><body><font color='red'>A</font><font color='blue'>B</font><font color='red'>C</font><font color='black'>D</font><font color='gray'>E</font><br><font color='red'>A</font><font color='blue'>B</font><font color='white'>C</font><font color='black'>D</font><font color='gray'>E</font><input type="button" value="Print this page" onclick="printpage()" /></body></html> (The font tag I used is deprecated but it's quick.)The reason I am printing a white character on white paper instead of printing a space has to do with trying to maintain vertical alignment of characters because browsers seem to compress whitespace, even for monospace fonts (I did only limited experiments). In the display, the letter C in the second row is not visible, as intended, while vertical alignment of the other characters is maintained. If the page is printed, the alignment is fine but the letter C in the second row is printed in gray. Independent of the merits, or lack thereof, of my approach, why is that? Can it be avoided? Thanks,GernotM

  • Like 1
Link to comment
Share on other sites

Why aren't you using css? You should add a little more markup to your script tags when they're above the body tag.

<head><script></script></head>

EDIT: The white printing as gray must be a printer thing.

Edited by niche
Link to comment
Share on other sites

I noticed that when I ran his script and was surprised that the function worked. How long has the script tag been that way? I've been running my JS with

<script type="text/javascript">

as long as I've been coding.

Edited by niche
Link to comment
Share on other sites

I noticed that when I ran his script and was surprised that the function worked. How long has the script tag been that way? I've been running my JS with
<script type="text/javascript">

as long as I've been coding.

HTML 5 does not require the type attribute anymore. The W3C has delared ECMAScript as the only standard scripting language for browsers.The <script> tag without the type or language attribute has always worked. The only problem was that it was invalid HTML.
  • Like 1
Link to comment
Share on other sites

Thanks Ingolme. The debates failed to entertain me and it's time to call it a day. I noticed you put in a long day too.

Edited by niche
Link to comment
Share on other sites

1. I didn't put the script tags above the body tag. The W3Schools example did. 2. Yes, the font attributes ought to be declared in CSS. But that's not the main issue here. 3. It's not a printer thing. I tried 3 different model printers (all inkjets). 4. I maligned monospace fonts wrongly. With Lucida Console, space comes out correctly so the issue is moot. Nevertheless, I find it curious that a character specified as 'white' comes out gray, i.e. white does not really equal 'no color'. Thanks,GernotM.

Link to comment
Share on other sites

Per the second post. I've done a lot of work on the browser - printer connection. I can say very credibly that the connection can be as much art as science. I remember specifically a situation that involved a the need to print a dotted line that was displayed as a dotted line, but printed as a sold. This and other similar situations drove me crazy. Then I accidentally, used an older browser version on a back-up system and viola!. The dotted line printed so now I'm very sensitive about printing issues with browsers. In general, I find older versions print more faithfully what's on the screen. That's valuable knowledge for some of our in-house apps, but may not be very comforting to the original poster. All I can say is wysiwyg when it comes to this issue, results vary with browser version, and aren't consistent (an existing capability may skip a couple of versions and magically show up again).

Edited by niche
Link to comment
Share on other sites

I agree completely with your opinion regarding the print surprises you can get with the different browsers. Since there is no way a combination of cyan, magenta, and yellow ink will give you white, and 'no ink' gives you white only on a white paper, a light gray may be the closest approximation to white deliberately chosen to print something on possibly non-white paper. Perhaps that is the rationale, and perhaps it is stated somewhere but I have never seen it expressed. On the other hand it may simply be a programming bug in window.print or (all?) printer software. After all, how many people are crazy enough to try to print a white character... Thanks for the discussion.GernotM

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...