- <?php
-
// starting word
-
$text = "My Text";
-
-
//Start MS Word
-
$Word = new COM("word.application") or die("Failure: Word did not start");
-
echo("WORD has started.");
-
-
//Formating the Font
-
$Word->Visible=0;
-
$Word->Documents->Add();
-
$Word->Selection->Font->Name = "Arial";
-
$Word->Selection->Font->Size = 12;
-
$Word->Selection->Font->ColorIndex = 4;
-
-
//Add text to the document
-
$Word->Selection->TypeText($text);
-
-
//Insert Image
-
$Word->Selection->InlineShapes->AddPicture("f:\Projects\fida\3.jpg");
-
-
//Save document
-
$Word->Documents[1]->SaveAs("f:\Projects\fida\myword.doc");
-
$Word->quit;
-
-
-
?>
I have tried the abouve code for embedding an image in document using php.But i am getting an error
WORD has started.
Quote:
Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Word<br/><b>Description:</b> This is not a valid file name. Try one or more of the following: * Check the path to make sure it was typed correctly. * Select a file from the list of files and folders.' in F:\Projects\fida\word.php:20
Stack trace:
#0 F:\Projects\fida\word.php(20): variant->AddPicture('f:\Projects?ida...')
#1 {main} thrown in F:\Projects\fida\word.php on line 20
Please help to get rid of these