Monthly Archives: April 2014

Printing the page

I had to go through the printing process as I got a new project from my cousin. On my way, I never ever did such a job which involved printers or hard copy format for the documents. Now that I had the job for that, I started looking up for some resources. I did know that I can use CTRL + P key command to print. But, how to integrate all that inside the HTML document, I was making up some assumptions. And this was what I got.

First thing was to print the page. So for that you can create a button element inside your HTML document and handle it using jQuery for the print event. Here is the code for that:

<button>Print</button>

/* Script part */
$('button').click(function () {
  window.print();
}

Now the browser would show a simple window, where you would get more options to control the printed version of the page. You can either set them there, or you can use the code to control the page layout even more better. What you would try here is CSS3’s Media Query.

Here is the example, lets assume we’re having a div inside the body element. Which is having the id of printable and all the other body is given the id of non-printable. Now in the CSS you were taught for the usage of Media Query.

You can use this code:

@media print {
  #printable {
    display: block;
  }
  #non-printable {
    display: none;
  }
}

That was enough here. Now you can use this code to view only the printable part of the page. Which would be helpfull to save the page and to get the desired output.

Some other tips you might need to use:

  1. Always use CSS3 media query to stylize the printable version.
  2. Always keep the width larger so that height of the page is less. Saves the page!
  3. Always keep the note on the page by clicking the button or by Print command. To keep a note on the printed version too.
  4. Keep the font-size short and easy to read.
  5. Use short sentences and good punctuations. It makes the document better to be read. Less words save the space
  6. Always remember to remove the margins and paddings from the body element. Printer would automatically add the margin and paddings to the page which would be enough.
Advertisements