Jump to content
  • Advertisement
Sign in to follow this  

[web] Printing from browsers

This topic is 3001 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, There are certain pages on my site that contain graphs and other tabular data that I would like to provide a "Print" button for; that, when clicked, launched the user's default print dialog and allows the user to print that page... However, I want to be able to only specify the graph or tables as part of the print. In fact, through this Print button, I don't want the user to be able (!) to print any other components of the page, including the traditional print headers and footers that most browsers insert automatically, such as showing the URL of the page being printed, page numbers, etc. Is this even possible? How can I basically declare certain sections/divs/etc. of my page printable and only allow those items to be printed through this custom Print button? No headers or footers. No requirement that the user first highlight the graph or table and then print "selected highlighted" in the print dialog... ? Thanks for any feedback! plywood

Share this post

Link to post
Share on other sites
Using regular HTML you are a little limited. You can use media="print" with stylesheets to include a stylesheet that is only used when printing, for example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Printing CSS</title>
<style type="text/css" media="print">
.not-printed {
display: none;
<p>This is printed.</p>
<p class="not-printed">This isn't.</p>

You will, however, not be able to remove the default browser information that is added to the page. For more control you will either have to head to server-side solutions (e.g. generate a PDF on the server and send that to the user to print off themselves) or rich client-side solutions (such as Flash or Silverlight).

Share this post

Link to post
Share on other sites
In addition to class="NotPrinted", you can also just restyle entire sections of the page inside your print-specific CSS. If you were wise enough to insert the header/footer in their own DIVs, you can just redeclare those sections as invisible, along with any other features that you don't want printed, or printed differently:

#header, #footer, .noprint { display: none; }

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!