Here's a simple example of printing formatted templates with MS Word.
To begin with, I've already built my invoice in Word and saved it as an RTF file.
In this case, I'm using "sampleInvoice.php"
Fields that will be replaced have been marked as ||CUSTOMER ID|| and so on.
<?php
$dataText = "";
if(!($fp= fopen ("C:\wordTest\sampleInvoice.rtf", "r"))) die ("Can't open");
$dataText = fread($fp, 2000000);
fclose ($fp);
$dataText = str_replace ("||CUSTOMER ID||",$customerIDValue, $dataText);
$timeStamp = time();
$saveFile = "C:/wordTemp/".$timeStamp."-invoice-".$customerIDValue.".rtf";
if(!($fq= fopen ($saveFile, "w+"))) die ("Can't open");
fwrite ($fq, $dataText);
fclose ($fq);
$word = new COM("word.application") or die("Unable to instantiate Word");
print "Loaded word version ($word->Version)\n";
$word->visible = true;
$word->Documents->Add();
$word->Documents->Open("$saveFile");
$word->ActiveDocument->PrintOut(1);
$word->Quit();
?>