So I have finally found some resources to help me get my PHP script to interact with MS Word and create a word document. I have been playing with some commands but am having trouble with getting the document to print.
I have done the following to create and write to and save a document:
// start MS Word
$word = new COM("word.application") or die("Unable to instantiate Word");
// create new doc
$word->Application->Documents->Add();
// write to page
$word->Selection->Font->Size = 12;
$word->Selection->Font->Name = "Arial";
$word->Selection->TypeText("text string goes here");
// Save
$new_file = "c:/trial.doc";
$word->Application->ActiveDocument->SaveAs($new_file);
// free the object
$word->Quit();
$word->Release();
$word = null;
This all works fine and creates the new documnet but I now want to enter a command to have the document printed on completion. I have used this:
//print
$word->PrintOut();
This does not seem to work though. How ever, I have not got a printer connected directly to my laptop. I have a printer driver installed for a printer I can connect to and when I set this printer as the default, it appears to add the print item to the print queue. I also have a printer I can connect to via a wireless network but when I set this printer as the default on my machine, the item does not print out. I know the printer works OK from MS Word as I can open the same document in word and print it.
Any suggestion as to where I am going wrong?