Skip to Content

Browsers seem to be the ultimate promoters of the paperless office. In fact, they make printing complex web pages a tedious task. Even printing the simplest page is far from WYSIWYG. And let’s not even go into problems such as Firefox thinking that everybody prints on Letter, instead of the A4 set in the Windows default printer settings. The printer sometimes tries its best to jabber the output too.

Due to all this, printing SDN weblogs isn’t as easy as clicking on the Print icon, certainly not where textareas are involved. The objective of textareas is to avoid taking in the whole page if the content is rather large. However one would normally expect  that all would become visible when printed. No such luck.

This is rather annoying if you want to hang the printout of your idols weblog – teenager wise – on the wall of your bedroom, or frame it and put it next to your picture of wife and kids on your desk. There are of course more serious applications of a printout as Faaiez Sallie states in this Printing of Weblogs.

When I was looking for a solution I wondered if I could use and extend the solution for How to print an SDN forum thread in Firefox in a nice and easy way. I knew it wouldn’t be that easy, since a textarea doesn’t have many properties to play with. So it took me a while and this “oneliner” is the result of my research :

class="style1">

<!code>

javascript:id=document.getElementById(%22iframecontent%22).contentWindow;ta=id.document.getElementsByTagName(%22TEXTAREA%22);

for (i=0; i<ta.length;i++) {cr=0; idx=ta[i].value.indexOf(”
“, 0);

while ( idx != -1 ) { cr +;idx = ta[i].value.indexOf(”
“, idx
1); }ta[i].rows=cr;}id.print();<!code>   

As with the bookmarklet principle from my earlier mentioned weblog, just copy and paste it (in one line!) and save as a bookmark.

I used Thomas Jung’s excellent web log on BSP a Developer’s Journal Part XIV – Consuming WebServices with ABAP as a test example and it works fine in Firefox & co. There is one pitfall though. Sometimes you get an uncaught exception: permission denied, due to the fact that you can’t do cross domain stuff. The solution is to retrieve the weblog with http://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/ instead of http://sdn.sap.com/sdn/weblogs.sdn?blog=/pub/wlg/

What does the code actually do? Let’s examine the code.

class="style1">

<!code>  id=document.getElementById(%22iframecontent%22).contentWindow;<!code>

 

getElementById returns the element whose ID is specified. The ID we specify (iframecontent) is the iframe containing the web log. The contentWindow property returns the window object for the frame.

class="style1">

<!code

ta=id.document.getElementsByTagName(%22TEXTAREA%22);<!code>

   

in this weblog, we gather all the textareas and put them in an array.

class="style1">

<!code>

  for (i=0; i<ta.length;i++) {<!code>

   

we loop over the array

class="style1">

<!code>

    cr=0;

    idx= ta[i].value.indexOf(”
“, 0);<!code>

   

we search for the first new line

class="style1">

<!code>

    while ( idx != -1  ){<!code>

   

as long as we didn’t reach the end

class="style1">

<!code>

          cr ++;<!code>

   

we increment the new line counter

class="style1">

<!code>

          idx = ta[i].value.indexOf(”
“, idx+1);}<!code>

   

and search for the next new line

class="style1">

<!code

    ta[i].rows=cr;}<!code>

   

the textarea needs to be resized

class="style1">

<!code

id.print();<!code>

   

and finally we print out the whole weblog

Of course, you can add some more fancy stuff, like resizing the width of the textareas, but that’s up to you to decide.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply