Friday, September 17, 2010

How to add print this button in blogger blog?

Some time readers want to print a article from your blog. They will use the "print" option from their web browser window. But this will print some unnecessary thinks like header,footer,sidebar,comments and so on. If you want to give the reader a clean print layout for your each post.Then this article is for you.
I am using CSS and JAVASCRIPT for this. Now lets do some CSS for print.
Go to Layout>Edit HTML tab
Search for the closing </head> tag.

Before </head> , add the following lines of code

<style media='print'  type='text/css'>
section, nav, article, aside, hgroup, header,  footer, #comments, .comments {display:  none;}
#main,.main {width: 95% ;}
</style>

Explanation:
  • The media='print' is used to tell the compiler that it’s a print style.
  • We do not want navigation bar, side bar, comment, footer area to display. so I use a small css code display: none;
  • To hide all this item. Now we want the article area will extent during printing. So I use width: 95%; for larger width. We can modify the width for better presentation.
Now preview and save the template.

Add a "Print this" link

To print more effectively add a "Print" link in each of your Blogger posts.
To add the print link,
Go to Layout>Edit HTML tab and ticked the "Expand Widget Templates" checkbox.
Now search for this line (Press Ctrl+F for quick search):
<data:post.body/>
Immediately after this line, paste one of these three sections of code:

<b:if  cond='data:blog.pageType == &quot;item&quot;'> 
<span style='background: url(http://i818.photobucket.com/albums/zz103/maidul/web%20resource/Print.png)
left no-repeat; padding-left: 28px;'>
<a  href='javascript:window.print()'>Print this post</a></span>
</b:if>
Explanation:
  • <b:if cond='data:blog.pageType == &quot;item&quot;'>is used to check if this currently showing full post.
  • <span style='background: url(http://i818.photobucket.com/albums/zz103/maidul/web%20resource/Print.png) left no-repeat; padding-left: 28px;'> is for styling the button.
  • <a href='javascript:window.print()'>Print this post</a> used for printing link.
Once you have added this code, save your template. These links will only be visible on post pages.
You can Subscribe via Email to get updated post
If you enjoyed this post, make sure you subscribe to rss feeds to receive new posts in a reader or via email.

2 comments:

  1. Very very useful information,
    thanks for the post...

    ReplyDelete
  2. This worked great for me, thanks! Just to mention, I wanted to show on a new line after the last post, so I added
    before it and that did the trick! Thanks again!

    ReplyDelete

OLDER POST HOME