Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format CSS for 8.5x11 inch printed pages

Tags:

I am looking for help setting up the initial DIV that will fit within the borders of the letter paper. I'll loop for dynamic page content ending each page with `page-break-after; always;.

I've been using the trial and error approach and have now run out of paper to trial with.

How do you setup the div container where positions relate to the paper margins?

Thank you!

like image 977
Chris Avatar asked Nov 17 '10 13:11

Chris


People also ask

How do you write a print page in CSS?

HTML, CSS and JavaScript You can use CSS to change the appearance of your web page when it's printed on a paper. You can specify one font for the screen version and another for the print version. You have seen @media rule in previous chapters. This rule allows you to specify different style for different media.


1 Answers

After using a CSS reset template, and with "shrink to page" turned off in print options I am able to make a DIV that is 7" (about 670px) wide and 9.5 (about 900px) high. I can position inside this box.

It translates fine between the printers I have connected. If my calculations are correct, the print DPI is about 95ppi.

#printPage
{
  margin: 0px;
  padding: 0px;
  width: 670px; /* width: 7in; */
  height: 900px; /* or height: 9.5in; */
  clear: both;
  background-color: gray;
  page-break-after: always;
}

Then positioning like this works:

#cube
{ 
  position: relative;
  top: 1in;
  left: 1in;
  width: 1in;
  height: 1in;
  background-color: white;
}
like image 142
Chris Avatar answered Sep 28 '22 08:09

Chris