Generating Formatted Microsoft Word Files with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Generating Formatted Microsoft Word Files with PHP

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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:)
Last edited by Benjamin on Sun Dec 05, 2004 8:36 pm, edited 1 time in total.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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.
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post 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
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post 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
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post 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
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post 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...)
Post Reply