View Full Version : PHP to generate MS Word -- print margin issue

05-14-2004, 09:02 PM
Hey guys,

So what I'm doing is generating an HTML document and storing it in a String. Then I'm sending the following headers:

header("Content-type: application/msword");
header("Content-Disposition: attachment; filename=disbursement.doc");
header("Pragma: no-cache");
header("Expires: 0");
print "$html_str";

Where my html is in $html_str.

Now I'm using CSS to do the fonts and alignments and all that stuff and it looks really good. The only thing is that I'd like the page to be setup with 0.25" margins all around and on legal size paper.

I'm just not sure how to go about this. I set the BODY tag's margins using the style property, but that did nothing..

Are there any headers I can send to tell MS Word to do this or any alternative CSS things I can set? Or is there a way to configure Word to open ALL documents defaulting them to Legal size and with those margins? I changed a template file called Normal.dot to do this, and when I open a New Word document it opens with the Legal settings etc.. but when I open this PHP generated Word document, it doesn't have those Legal settings, margins, etc..

I'm pretty clueless here, and all the tutorials I've been looking at use COM classes, but I'm not sure that's the route I want to take. With the COM route, would that still open the document in Word on the client's machine?

Thanks in advance for any feedback,

05-15-2004, 12:11 AM
It would still be nice to know if it's possible to do this using CSS or something, but for the meanwhile, I created a Macro in Word to change the margins and the paper size to legal, and attached a menu item to it.

I'm sort of lucky that the office uses a shared normal.dot so I put the macro in there and so everyone gets that button, and can use it as necessary.