Ralph Varjabedian
Coding is a systematic art

Printer Friendly Pages in 5 minutes

Friday, November 14, 2008 5:00 PM

I answered a post the other day about an easy way to have printer friendly look of pages in your web application and I decided to blog it here. You just need 5 minutes to have all your pages in your web application printer ready, ok maybe a bit more, like 10 minutes :)

When you design your web application, have your pages implement a master page, let us call it MainMaster.Master. Create another master page, call it PrinterFriendlyMaster.Master and make sure it has the same content holders as your MainMaster.Master, however make it printer friendly, without a header, maybe simpler footer, no background color, maybe different CSS files, etc... anything you need to do to have it ready for printers. Create a base class for all your pages, let us call it BasePage, it is a simple class like this:

using System;
using System.Web;

namespace telephone.NOC
    public class BasePage : System.Web.UI.Page
        protected void Page_PreInit(object sender, EventArgs e)
            if (Request["print"] != null)
                Page.MasterPageFile = "~/PrinterFriendlyPage.master";

Have all your pages derive from BasePage class.

Now at runtime, when you add a query string to a URL with print=1 the Page_PreInit of BasePage will detect that and will switch the master page dynamically to the printer friendly one, simple, modular and fast to implement.


# re: Printer Friendly Pages in 5 minutes

thank you for this cool post.
i read it and i analyse it for me but i think this is a extra and make the website into large sapce(have a lot space in your webpage). if you have other way please write about it.
1/8/2009 3:39 PM | Rebwar

# re: Printer Friendly Pages in 5 minutes

Hi, I am not sure how exactly you are using it, but you should not have any extra spaces, if you want show me an example. 1/12/2009 11:56 AM | Ralph Varjabedian

Post a comment


Please add 6 and 4 and type the answer here: