473,800 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting HTML content to word doc using PHP code

1 New Member
Hi,

I want to Convert a HTML content to word doc using PHP code. pls help
Nov 12 '07 #1
2 4680
Atli
5,058 Recognized Expert Expert
Hi. Welcome to TSDN!

The simplest way to create a Word document is to simply use the Filesystem Functions to create a .doc file containing HTML markup.

The other, slightly more complex way, is to use COM objects to create an actual Word Document. In order for this method to work, you need to have Word installed on the server. Then you can do something like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # Create a Word object
  3. $word = new COM("word.application") or die ("Couldn't create a Word object");
  4. $word->visible = 1;
  5.  
  6. # Create a document and add some text
  7. $word->Documents->Add();
  8. $word->Selection->TypeText("This document was created in PHP!");
  9.  
  10. # Save the document and release the Word object
  11. $word->Documents[1]->SaveAs("sampleword.doc");
  12. $word->Quit();
  13. $word->Release();
  14. $word = null;
  15. ?>
  16.  
Note that Microsoft recommends against using Office in this manner. See this article for more on that.

The last and most complex method would be to create your own Word parser. To do this you would need pretty detailed info on the inner workings of a Word Document.
Nov 12 '07 #2
pwiegers
1 New Member
Hi,

The last and most complex method would be to create your own Word parser. To do this you would need pretty detailed info on the inner workings of a Word Document.
I've often wondered about a 4th way: create OO.o XML (this should be relatively easy), and then callling OpenOffice to re-save the XML as .doc I've never gotten around to trying this, but it should not be hard..
It would, I think, be the easiest way if you want extensive formatting in .doc....

Anybody tried this?

greetz,

Paul
Nov 12 '07 #3

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

Similar topics

2
8029
by: Phil Powell | last post by:
Based on the information I read in www.php.net on the header command I wrote a dummy test script to try to convert the contents of $stuff to MS Word downloadable format: http://www.php.net/header Code: $stuff = '<html><head><title>stuff</title></head><body><b>Hello</b>
17
29837
by: mickjames | last post by:
Hi, I'd like to include the whole web page content (as opposed to just the headlines) into RSS/XML to enable people to read them via rss feed readers. Question: how to convert HTML elements such as href, img, b, p, etc into XML? I've seen someone use the following in their RSS feed but I don't like it because <pre> doesn't produce a nice format:
20
7358
by: Al Moritz | last post by:
Hi all, I was always told that the conversion of Word files to HTML as done by Word itself sucks - you get a lot of unnecessary code that can influence the design on web browsers other than Internet Explorer. Our computer expert in my company had told me already a while ago that I should learn HTML and encode myself. I was never inclined to do so (I am no computer expert), and when upon his suggestion I looked how my pages (converted to...
1
3417
by: unotin | last post by:
I have an application in ASP that exports to Word using the Response.ContentType method. The application references another ASP page through the img tag that uses a Response.BinaryWrite (of an img content type) for its output. In other words: App A.ASP contains the code: <%Response.ContentType = "application/vnd-msword"%> <img src="B.ASP">
3
2165
by: adam | last post by:
Hi, I'm building a tree control that lazily loads branches of the tree using the document.load() method. The external XML document that is loaded is generated by a servlet as XHTML. What I would like to do is to add the new tree branch to the correct place in the document in the browser window using the innerHTML property of the parent node.
1
1987
by: KK | last post by:
Hi, I need to save certain content to SQL server and then use SQL Server indexing facility to search. SQL Server have recomended using Image data type with a filter type (for .htm, .doc etc..) Now, because of this I save normal html content also in binary format in the Image field.
1
1802
by: darrel | last post by:
I have two issues: 1) The WYSIWYG content editor we're using for our CMS doesn't truly support xhtml. 2) .net doesn't truly support xhtml my question is if there is a .net library/class/component that can convert from html to xhtml?
9
6738
by: anupamjain | last post by:
Hi, After 2 weeks of search/hit-and-trial I finally thought to revert to the group to find solution to my problem.(something I should have done much earlier) This is the deal : On a JSP page, I want to grab a URL and parse /change the HTML and send it to the JSP page. I take the URL from the user in a textbox (not the
11
16586
by: Grischa Brockhaus | last post by:
Hi, I'm trying to produce a div layout containing a header on the top with fixed height, a footer on the bottom using fixed height and a content layer using what's left of the browsers window. So my header div is defined at top:0; height:40px , my footer is defined as bottom:0; height:40px and the content is defined as top:40px;bottom:40px; This works very well with firefox but doesn't work with IE, as IE ignores the bottom statement...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10035
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7580
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.