Printing is a built in functionality of the web browser you use, and unlike in a desktop application you don't need to worry about the technical functionality of printing here. Just select File > Print and it will take care of the rest (given that your system is setup properly for printing).
However, you need to make your web pages out put print compatible.
First thing you will need is a two set of CSS because you will need to style the page differently when printing. This can be easily done by using CSS media type. Your either define
block in your CSS, or you can include a separate style sheet targeted for print media.
- <link href="style.css" rel="stylesheet" type="text/css" media="all" /> <!-- CSS for all (screen display + printing) -->
-
<link href="print.css" rel="stylesheet" type="text/css" media="print" /> <!-- CSS for printing only -->
For more details see
w3schools article "CSS Media Types" on this.
Another thing is, you should have a fluid HTML layout in your web page, meaning you should design the page layout using DIV tags instead of TABLEs.
For a single (print) page this will not make a different, but TABLE layout designs give you unpredictable results in where page breaks should occur.
Speaking of page breaks, you should use them wisely. Making sure that page breaks doesn't occur with in block elements, floated elements or elements with borders is very important otherwise browsers might ignore them completely and it will result in missing pages in the print.
Page breaks also doesn't work in absolutely positioned elements.
More details can be found in
this "CSS page-break-after" w3schools article.