0

I'm currently using the Word COM object which is massively flaky but does the job.

Unfortunately the settings have been changed on the server so I can no longer access this, and am looking at alternatives.

I quite like the idea of the fopen route, which apparently lets you style things in HTML for use on the page, but whenever I try this (or use examples from the web) it just places the HTML code directly into the page 'as is' - not very useful.

Can anyone please recommend a good alternative to this, and the COM object? If indeed there is one...? My main requirements are for the documents to be saved on the server, as well as allowing me to enter an image into the header.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Nick
  • 1,233
  • 13
  • 26
  • 37
  • I am toying with this, but can't change the margins on the body, and the image is almost exactly the page width so with a 1 inch margin, it looks silly :/ – Nick Apr 21 '11 at 13:34
  • $fp = fopen("test.doc", 'w+'); $str = " Test"; fwrite($fp, $str); fclose($fp); – Nick Apr 21 '11 at 13:35

1 Answers1

2

Have you considered PHPWord?

Note that it can only create the newer Office Open XML (Office 2007+) format documents.

thirtydot
  • 224,678
  • 48
  • 389
  • 349
  • Many thanks for the recommendation, unfortunately everyone here uses the old office so this isn't much use to me :( – Nick Apr 21 '11 at 13:22
  • 2
    From [the documentation](http://phpword.codeplex.com/documentation): `"For opening by PHPWord created files in Microsoft Office < 2007 you need the "Microsoft Office Compatibility Pack".` ([http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=941b3470-3ae9-4aee-8f43-c6bb74cd1466](http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=941b3470-3ae9-4aee-8f43-c6bb74cd1466)). It's *so much easier* if you stick to the newer document format. The old format is a nightmare. – thirtydot Apr 21 '11 at 13:24
  • thanks, but that'd require IT having to install it on around 2,000 machines here which is quite unlikely :( – Nick Apr 21 '11 at 13:32
  • Ah well, I was hoping you had a smaller office :) In that case, this won't work for you. Out of curiosity, what version of Office is installed on all those computers? – thirtydot Apr 21 '11 at 13:37
  • Office 2003 (without the compatibility pack!) – Nick Apr 21 '11 at 13:38
  • 1
    Unfortunately, I can't easily help you, as I don't have that version installed anywhere handy. [I did toy with](http://stackoverflow.com/questions/4415729/how-can-i-save-content-of-current-webpage-in-word-through-php/4415830#4415830) the kind of idea you have in the comments on your question. – thirtydot Apr 21 '11 at 13:40
  • Can you run custom executables on your web server? OpenOffice might be able to help you. I'm just guessing here, but maybe you could make a `.docx` and convert it to `.doc` using OpenOffice? Also, have you considered generating PDFs instead? – thirtydot Apr 21 '11 at 13:45
  • Ah, thank you - I'm thinking that could be the best option, but I can't get the damn page margin to lower... sounds silly but it's huge right now and seriously needs to be made a lot smaller for it to be a viable option :( – Nick Apr 21 '11 at 13:50
  • No chance of running custom executables unfortunately, document also has to be generated on the fly – Nick Apr 21 '11 at 13:50
  • I meant use OpenOffice on the command line to do the conversion automatically, but if you can't run custom executables, it doesn't matter. If PDFs are viable then I would recommend [wkhtmltopdf](http://code.google.com/p/wkhtmltopdf/), but that requires running a custom program. Instead, try [dompdf](http://code.google.com/p/dompdf/) - it doesn't have any dependencies. – thirtydot Apr 21 '11 at 13:54
  • PDF also isn't an option unfortunately since they need to edit the documents afterwards - d'oh! ^_^ So sorry to keep going back to it, but using the example in my comments and that you mentioned before, is there anyway at all to change the page margins? I guess not:) – Nick Apr 21 '11 at 13:56
  • Ah well. I have no idea. Have you tried stuff like `` ? – thirtydot Apr 21 '11 at 14:00
  • Unfortunately yes, but only set to 0... I'll try setting it to 50px (or whatever) asap :D Thank you – Nick Apr 21 '11 at 20:53