467,080 Members | 947 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,080 developers. It's quick & easy.

Embedding an image in document using php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // starting word
  3. $text = "My Text";
  4.  
  5. //Start MS Word
  6. $Word = new COM("word.application") or die("Failure: Word did not start");
  7. echo("WORD has started.");
  8.  
  9. //Formating the Font
  10. $Word->Visible=0;
  11. $Word->Documents->Add();
  12. $Word->Selection->Font->Name = "Arial";
  13. $Word->Selection->Font->Size = 12;
  14. $Word->Selection->Font->ColorIndex = 4;
  15.  
  16. //Add text to the document
  17. $Word->Selection->TypeText($text);
  18.  
  19. //Insert Image
  20. $Word->Selection->InlineShapes->AddPicture("f:\Projects\fida\3.jpg");
  21.  
  22. //Save document
  23. $Word->Documents[1]->SaveAs("f:\Projects\fida\myword.doc");
  24. $Word->quit;
  25.  
  26.  
  27. ?>
I have tried the abouve code for embedding an image in document using php.But i am getting an error
WORD has started.
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
Oct 19 '09 #1
  • viewed: 4067
Share:
6 Replies
Dormilich
Expert Mod 8TB
backslashes are the general escape character in PHP. either you use single quotation marks (unparsed string) or you escape the backslashes (with backslashes).

\f - form feed character
Oct 19 '09 #2
Thanks for your help!it worked
Oct 20 '09 #3
Is there any function to set up header and footer in a word document using php
Oct 20 '09 #4
Dormilich
Expert Mod 8TB
not that Iím aware of, seems rather unlikely (most servers do not run windows)
Oct 20 '09 #5
i have searched through so many documents ,but not found nay way to set header and footer for a word document using php while i create the document using COM functions.Its very urgent for me
Oct 20 '09 #6
Dormilich
Expert Mod 8TB
I canít help you much there, never used COM objects before. Judging from the manual Iíd say you need the Word OLE Interface (because that whatís COM working with) to find header/footer functionality.
Oct 20 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Victor Fees | last post: by
5 posts views Thread by Joe Bonavita | last post: by
7 posts views Thread by David Thielen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.