Sending a page to print (Ctrl + p)

Printing pages in a nice format.

You might know that a website should include a print option link on the pages of your website. But what about the user doing the old Ctrl+P short-cut from the keyboard? How do you handle this, read on.

Start with the following CSS inclusion in your print.css page (you do have one don’t you?) and just add/change whichever styles you need to appear on the print screen. You can use the FireBug tool to find the elements you wish to manipulate.

@media print {
  .breadcrumb, img, #menu-nav {
    display:none;
  }
}

If you don’t have a print.css in your website, you can set this up by adding the following snippet to your index.html or blahblah.php file in the head section. You must of course also add the print.css file to the relevant directory you indicate it will live in.

<link rel="stylesheet" href="/template/example/css/print.css" type="text/css" media="print" />

The Joomla method (2.5.x/3.x.x), to be added to your master index.php file at the relevant template root.

JFactory::getDocument()->addStyleSheet($this->baseurl.'/templates/'.$this->template.'/css/print.css', $type = 'text/css', $media = 'print');