user2666633
user2666633

Reputation: 340

How to insert php variables to word doc template and also convert to pdf

I am still new to programmer but i am doing just good.

This is what i attempt to achieve, get a template in word doc with some texts and blank spaces, then populate those spaces with variables coming from a form field processed in php. e.g

**in Microsoft word file i have:** 
 Name: 
 Age:
 Sex:

**Then in my php file**
I have 
$name;
$age;
$sex;

so i want to populate the word doc with the variables from the processed form and also be able to download the form already populated in same .doc and also PDF format

Upvotes: 0

Views: 2461

Answers (1)

Guido Leenders
Guido Leenders

Reputation: 4262

I understand that the document needs to be downloaded from a web application and probably needs no extensive customising by the user. In that case, I would recommend using docx format instead of doc, or RTF.

In RTF you will have problems making tables look good, dito headings/footers, but it is further rather easy and portable to generate. If you choose docx, you can generate the document as XML and compress. There are various libraries for this purpose.

Since you indicate you will also need a PDF representation, I would recommend choosing a library that generates to DOCX as well as RTF and PDF. For Java, my advice would be JasperReports. For PHP, being not an enterprise platform (end of flame war), you might consider alternatives such as http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2009/12/18/7923.aspx or LiveDOCX.

If you choose to generate the two output types through different means (introducing more maintenance and possible future bugs), I would recommend generating RTF and publishing the RTF as PDF, for instance as described in rtf format to pdf

Upvotes: 1

Related Questions