473,390 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

Embedding an image in document using php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // starting word
  3. $text = "My Text";
  5. //Start MS Word
  6. $Word = new COM("word.application") or die("Failure: Word did not start");
  7. echo("WORD has started.");
  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;
  16. //Add text to the document
  17. $Word->Selection->TypeText($text);
  19. //Insert Image
  20. $Word->Selection->InlineShapes->AddPicture("f:\Projects\fida\3.jpg");
  22. //Save document
  23. $Word->Documents[1]->SaveAs("f:\Projects\fida\myword.doc");
  24. $Word->quit;
  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
6 4418
8,658 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
8,658 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
8,658 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

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

Similar topics

by: Victor Fees | last post by:
I have an XML string in a database that I would like to display using XSLT. All of that works like a champ, but I can't figure out how to embed the XML inside an ASPX page. For example, I have...
by: FC | last post by:
Hello folks, I was wondering if there any other method of achieving the following: I have a XSL transformation outputting a SVG document. For reasons too long to explain here, I must embed a CSS...
by: Joe Bonavita | last post by:
I need to change images with the click of a button but I don't want the entire page to refresh so I thought I should just use an embedded page. I'm trying to use the <object> tag for this but can't...
by: Robin Tucker | last post by:
At the moment I have place-holders in my Word document (before you say it, yes I've posted this query in the VBA newsgroups but they are a little slow - in fact reply was non-existent!). I'm...
by: David Thielen | last post by:
Hi; Is there a way to embed images in the response rather than writing them to disk and having an <img ...> tag? And if so, how is it done and what browsers support it? -- thanks - dave
by: Edward | last post by:
I have been doing some research about embedding images in HTML using the data URL src method of the format: <img src="/-/data:image/gif;base64,<DATA>"> My question is, how does one generate...
by: hq4000 | last post by:
Given AStyleSheet.xsl : <AStyleSheet> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.mytest.mytest2.mytest3.com" version="1.0"> <xsl:output method="xml"...
by: pavan anumula | last post by:
I have a requirement When i click on button, i have to initiate an email with the to address, subject, and body should contain an image and the text . Problem : I cannot embed the image using...
by: neovantage | last post by:
Hey all, I am using a PHP script which creates headings at run time in a sense at page execution. I am stuck a with a very little problem which i am sure i will have the solution from experts. ...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.