Creating Doc file using PHP form



Hello All

Basically i have a form created in php. Now what i want is that whenever any visitor fill up this form and click on submit button. The information filled in form should saved in DOC file in Word format. I am able to store in txt format. But i am getting problem in DOC file doing the same.

Thanks in advance for your valuable time for replying me.


Vikas Garg
You can use the COM interface to interact with Word, but it requires that Word is actually running on the server and isn't the best solution anyway. Here is an example of how to do it, but you'll have to dig up all of Word's COM functions yourself.

The real solution is to dump Word and use PDF. PHP has an entire PDF library, there are plenty of good tutorials for it out there, and PDF is a better and more universal format than Word.
Thanks for your help.

Your reply was really very helpfull to me.

Even i also think that using PDF library would be more banificiary then COm interface of word. COM interface to word is working fine, if i use it offline. But i am getting the following error while using it onlie. Is it due to the COM Componenets are not installed on the server. How can i check whether it is installed or not?

$content = "Insert Sample Text Here\t\tThis starts a new paragraph line.";
$word= new COM("word.application") or die("Unable to create Word document");
print "Loaded Word, version {$word->Version}\n";
$word->Visible = 0;
$word->Selection->PageSetup->LeftMargin = '1"';
$word->Selection->PageSetup->RightMargin = '1"';
$word->Selection->Font->Name = 'Helvetica';
$word->Selection->Font->Size = 15;
$word->Selection->Font->Bold = 1;
$word->Selection->Font->Animation = 2;
$word->Selection->Font->ColorIndex= 11; //wdDarkRed = 13
echo "done";

script is on

Even i also tried out the folowing code for creating the PDF file. But i dont got sucess. I am not understanding, where i am wrong?

$pdf = pdf_new();
pdf_open_file($pdf, "test.pdf");
pdf_set_info($pdf, "Author", "Uwe Steinmann");
pdf_set_info($pdf, "Title", "Test for PHP wrapper of PDFlib 2.0");
pdf_set_info($pdf, "Creator", "See Author");
pdf_set_info($pdf, "Subject", "Testing");
pdf_begin_page($pdf, 595, 842);
pdf_add_outline($pdf, "Page 1");
$font = pdf_findfont($pdf, "Times New Roman", "winansi", 1);
pdf_setfont($pdf, $font, 10);
pdf_set_value($pdf, "textrendering", 1);
pdf_show_xy($pdf, "Times Roman outlined", 50, 750);
pdf_moveto($pdf, 50, 740);
pdf_lineto($pdf, 330, 740);
echo "<A HREF=getpdf.php>finished</A>";

you can view it at


Vikas Garg
I am getting the following error

Fatal error: PDFlib error: [2100] PDF_begin_page: Function must not be called in 'object' scope in /home/dinsol/public_html/vikas/create_pdf.php on line 8

Vikas Garg