Page 1 of 1

Setting page margins

Posted: Tue Apr 18, 2006 11:41 pm
by tristanlee85
I figure this is something that is setup through browser/OS settings, but is there any way to change the page margins of a webpage using PHP, HTML, etc.? I want a page to print starting at almost the very top of the page. Here is how I have my HTMl currently set:

Code: Select all

<body leftmargin="0px" topmargin="0px" marginwidth="0px" marginheight="0px">
It helped a little bit, but are there any other methods?

Posted: Tue Apr 18, 2006 11:43 pm
by feyd
You have little control over it since the browser and OS have final say as to what margins are used. If you generated a PDF, it's a little bit easier to control, but again, the reader and OS can alter it outside of your own control.

Posted: Wed Apr 19, 2006 3:05 am
by Oren
Why don't you use CSS?

Posted: Wed Apr 19, 2006 5:19 am
by Chris Corbyn
Oren wrote:Why don't you use CSS?
Yep, CSS can have different settings for printers than it does for screens, and projectors.

Code: Select all

<style type="text/css" media="print">
body {
    padding: 0;
    margin: 0;
}
</style>
However, the printer will most likely add a small margin anyway... I doubt you can avoid that, even with PDF most home-printers have some sort of minimum margin.

Posted: Wed Apr 19, 2006 5:33 am
by Oren
d11wtq wrote:However, the printer will most likely add a small margin anyway... I doubt you can avoid that, even with PDF most home-printers have some sort of minimum margin.
Well, it is possible. There are printers that do that.

P.S I'm not sure he was talking about printing the page on a sheet of paper.

Posted: Wed Apr 19, 2006 9:45 am
by tristanlee85
Well, when I print this page out, there is about 3/4" white space on the top and botom of the page and I was wanting to fill that space of possible. Yes, I'm printing out the page to the printer.

Posted: Wed Apr 19, 2006 9:59 am
by RobertGonzalez
I think this will have more to do with the users' browser page setup than how you use CSS. If you set your page setup margins to .25" across the board you will get smaller edges on the paper when printing than if they were set to 1". And I don't think you can write code that will change a user's browser settings (though I could be wrong about that).

Posted: Wed Apr 19, 2006 10:08 am
by Oren
Most home-printers have some limitations and cannot print on the edge of the paper. Try changing the printer's settings and play with it.

Posted: Wed Apr 19, 2006 10:10 am
by tristanlee85
That would seem like a security issue there. The CSS helped a little bit though. With the default settings on my Linux machine (Firefox) and on Windows (Firefox and IE), they printed out fine.

Posted: Wed Apr 19, 2006 10:13 am
by tristanlee85
My only problem is that I have the page set to the max. Meaning, when it prints out, it's using all the space possible because the page is that long. Also, it can only be one page so that's why Im worried about it. This is going to be used by multiple users so I don't want to make them have to change printer settings just to print it. I think I'm good though. the CSS added a little more room to play with and it's all on 1 page now.

Posted: Wed Apr 19, 2006 10:15 am
by feyd
If printing is critical, generate a PDF. It's far easier to control than getting a web page to look right when printed from the multitude of browsers and OS's out there.