I have a form with some text areas that allow a scroll bar when the text exceeds the text box. The user would like to be able to print the screen, and this text is not visible. How do I make all of the text visible for just printing? Am I better of making a print to pdf link or something?
Share
You cannot solve this problem with CSS alone.
Why Pure-CSS Solutions are Insufficient (with demo)
Let me convince you the answers involving print stylesheets and
overflow: visibleare insufficient. Open this page and look at the source. Just what they suggested, right? Now print preview it (in, say, Chrome 13 on OS X, like me). Note that you can only see a line or two of the note when you attempt to print!Here’s the URL for my test case again: https://alanhogan.github.io/web-experiments/print_textarea.html
Solutions:
A JavaScript link that opens a new window and writes the contents of the textarea to it for printing. Or:
When the textarea is updated, copy its contents to another element that that his hidden for screen but displayed when printed.
(If your
textareais read-only, then a server-side solution is also workable.)Note that
textareas treat whitespace differently than HTML does by default, so you should consider applying the CSSwhite-space: pre-wrap;in the new window you open or to your helperdiv, respectively. IE7 and older do not understandpre-wraphowever, so if that is an issue, either accept it or use a workaround for them. or make the popup window actually plain text, literally served with a media typetext/plain(which probably requires a server-side component).The “Print Helper” Solution (with code + demo)
I have created a demo of one JavaScript technique.
The core concept is copying the textarea contents to another print helper. Code follows.
HTML:
CSS (all / non-print):
CSS (print):
Javascript (with jQuery):
Again, the successful JavaScript-based demo is at https://alanhogan.github.io/web-experiments/print_textarea_js.html.