Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP to generate MS Word -- print margin issue

    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:
    PHP Code:
     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,
    Sadiq.

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sorted it out.. kind of

    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.

    Sadiq.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •