473,509 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Embedding an image in document using php

8 New Member
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
6 4427
Dormilich
8,658 Recognized Expert Moderator Expert
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
Sajeena
8 New Member
Thanks for your help!it worked
Oct 20 '09 #3
Sajeena
8 New Member
Is there any function to set up header and footer in a word document using php
Oct 20 '09 #4
Dormilich
8,658 Recognized Expert Moderator Expert
not that I’m aware of, seems rather unlikely (most servers do not run windows)
Oct 20 '09 #5
Sajeena
8 New Member
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
8,658 Recognized Expert Moderator Expert
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

5
611
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...
4
3292
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...
5
1383
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...
0
1898
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...
7
2423
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
6
22777
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...
0
1409
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"...
7
7441
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...
1
3378
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. ...
0
7237
marktang
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,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7073
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...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.