Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you make a web page send to the printer something different than what's in the browser window?

Google Maps used to do this bit where when you hit the "Print" link, what would be sent to the printer wasn't exactly what you had on the screen, but rather a differently-formatted version of mostly the same information.

It appears that they've largely moved away from this concept (I guess people didn't understand it) and most websites have a "print version" of things like articles and so forth.

But if you wanted to make a webpage such that a "printer friendly" version of the page is what gets sent to the printer without having to make a separate page for it, how would you do that?

like image 587
Tom Kidd Avatar asked Sep 17 '08 16:09

Tom Kidd


People also ask

How do I choose what to print from a website?

Just select the desired text on the current page and press CTRL+P. This will bring up the Print dialog, where you can simply select the "Selection" option there.

How do I print certain pages of a website?

Open the print dialog by pressing Ctrl + P . In the General tab, choose Pages from the Range section. Type the numbers of the pages you want to print in the text box, separated by commas.

How do I print a specific section in HTML?

You can use this function for print a specific area of web page or full web page content. Use printPageArea() function on onclick event of print button element and provide the content area div ID which you want to print.


1 Answers

The @media rule in CSS can be used to define alternate rules for print.This is often used to hide navigation and change the style to fit print better:

@media print {
  .sidebar { display: none; }
}

You can also link a seperate stylesheet for print:

<link rel="stylesheet" href="print.css" type="text/css" media="print" />
like image 95
JacquesB Avatar answered Sep 30 '22 17:09

JacquesB