Page 1 of 1

Generating Formatted Microsoft Word Files with PHP

Posted: Sun Dec 05, 2004 8:15 pm
by nigma
Is there a way to use PHP to generate formatted microsoft word files? By formatted I mean like specify font face, color, etc. throughout the document.

Posted: Sun Dec 05, 2004 8:21 pm
by Benjamin
I highly doubt it. It is possible but you most likely would have to write your own script and you would be working with binary data. You may want to look into the .pdf format instead. There are scripts for creating .pdf files.

Posted: Sun Dec 05, 2004 8:26 pm
by nigma
I did some googling and found a way using COM objects.

Check the article out at PHPBuilder: http://www.phpbuilder.com/columns/yunus20031124.php3

Posted: Sun Dec 05, 2004 8:30 pm
by Benjamin
Cool, that is a good idea. An even easier way to do that would be to save a word document with predefined strings in it which would be modified using str_replace.

Then you just open the file using php, replace whatever you want, and then save it to another name or send it to a browser.

I can dig that:)

Posted: Sun Dec 05, 2004 8:35 pm
by nigma
Haha, I'll leave the topic around here so that maybe people with the same question in the future can wonder upon it.

Posted: Sun Dec 05, 2004 10:09 pm
by fractalvibes
Yeah, as long as you are running a Win server and have Word installed on the server a com object can instantiate and call methods of the Word object....really PDF is a better format for publication of documents - we use a com component that can translate everything but the kitchen sink into pdf format.

fv

Posted: Mon Dec 06, 2004 2:21 am
by mchaggis
Yes PDF is great, but RTF is another option, especially if the aim is to send it to the browser so that it can be opened and maybe editing.

RTF, has the advantage of formatting like .doc files but is formed by plain text. :D

Posted: Mon Dec 06, 2004 7:15 pm
by fractalvibes
Yes, if editing is desired, the RTF option would be good. I think people choose PDF because they don't want the document meddled with, that and Acrobat is so ubiquitous.

fv

Posted: Mon Dec 06, 2004 8:31 pm
by Shendemiar
agtlewis wrote:Cool, that is a good idea. An even easier way to do that would be to save a word document with predefined strings in it which would be modified using str_replace.

Then you just open the file using php, replace whatever you want, and then save it to another name or send it to a browser.

I can dig that:)
Thats cheating... (bit genius cheating indeed...)