Dynamically Create Word Document

theknight571

Platinum Member
Mar 23, 2001
2,896
2
81
I'm working on a project where the user can log in, supply their information to us and request a letter (for various reasons).

On our end, we review their information to make sure they're eligible for the requested letter and then we generate the actual printed letter for them to pickup. (They need to be here to show proof of ID etc... which is why we don't email it or similar alternative.)

What I was wondering if I can do, and so far my Google skills are failing me, is to setup a MS Word "template" and somehow pass the information to it when a button is clicked.

For example...

I log in and check the information, it all checks out, I hit the print button and a Word document opens already formatted and details filled in etc... ready to print.

Currently we take the information and create the word document manually.

We're using PHP and some Javascript so far in this project.

Thanks in advance

 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Does it have to be Word? It's much easier to generate a PDF document instead.
 

theknight571

Platinum Member
Mar 23, 2001
2,896
2
81
I was thinking Word in case some editing needed to take place.

I'd be open to other ideas though (other than plain text files... it has to look nice:)).
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
If you're using Word 2007 you could try generating the simplest possible word XML docx purely from code.

It's probably simplest to learn to use the mail merge features in Word, create the mail merge template doc, then have your PHP write out the merge data to use with the template probably as a comma-delimited text file.

"Dear MERGE_FIELD_1,
Little MERGE_FIELD_2 could not make it to school today because a dog ate his MERGE_FIELD_3. That's gonna leave a mark.
Sincerely,
MERGE_FIELD_4"
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
If you were to use ASP.NET you could simply use ActiveX automation or you can create an Office 2007 Document template using Visual Studio Tools For Office and have the template call a web service(provided by your php code) to retrieve the data and populate the content.