Read word and output as HTML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Read word and output as HTML

Post by JayBird »

Im looking to read word files and diplay the info as HTML.

Not really sure where to begin.

I've hard COM mentioned a lot, but haven't got a clue about that at all.

Any pointers?

Thanks

Mark
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

word files? You mean like myfile.doc - a Microsoft Word file.

-Nay
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

yup, thats exactly what i mean ;)

Mark
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

goooogle ownz j00 & also this
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

okay, i got a script.

Code: Select all

<?

// starting word
$word = new COM("word.application") or die("Unable to instanciate Word");

// if you want see thw World interface the value must be '1' else '0'
$word->Visible = 0;

//doc file location
$word->Documents->Open("c:\\first.doc");

//html file location  '8' mean HTML format
$word->Documents[1]->SaveAs("c:\\test_doc.html",8);

//closing word
$word->Quit();

//free the object from the memory
$word->Release();
$word = null;

?>
But, do i need to change anything in my PHP to allow the use of COM?

Can't see anything in the manual.

The script above when run, just sits there in the browser and nerver ends and never outputs anything?

Mark
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you should try it as console-application first. Maybe there's a popup and the task is never finished. I remember when I did this in a c++-class there were some unexpected message boxes, e.g. a confirmation request because of losing some formatting informations when saving as html. And there was a property to be set to avoid the UI-elements.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

console-application? How would i do that?

Mark
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

just run the script from a dos box, e.g.

Code: Select all

d:\path\to\php.exe -f e:\path\to\script.php
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

when i run it from the command line, it works perfectly!?

So why not in the broswer?

Mark
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

-- caution: wild guessing follows --
remember the nag screen when you started ms office/word for the first time? That one where you should enter your name, your initials and whatever. The webserver probably handles the request with another account than the one that has been configured. So maybe it's trying to show that screen again for the new user, after all the usual word.exe is started for the word.application object. By default a win32-service is not allowed to display UI elements on the desktop, i.e. if it uses the "local system" account.
It would fit the behaviour you've descripted. But I've banned ms office completely from my box (no I'm not a no-m$ stickler, simply no need for it ;) ) so I can't test it.
From the services-applet you can open the property sheet of the webserver. If it's configured to use "local system" you might try the checkbox right below that setting, allowing the service to access the default desktop.
But as mentioned: it's a long shot.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

what is the services-applet? Im on win98 with apache.

Is there definately no setting in the php.ini that enables diasbles COM?

THanks

Mark
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

There are these settings, nut i have no idea what they do

com.allow_dcom "0" PHP_INI_SYSTEM
com.autoregister_typelib "0" PHP_INI_SYSTEM
com.autoregister_verbose "0" PHP_INI_SYSTEM
com.autoregister_casesensitive "1" PHP_INI_SYSTEM
com.typelib_file "" PHP_INI_SYSTEM


Mark
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

found this on the PHP manual
It should be noted that to run anything that needs to interact with the UI (the word example), one needs to ensure that the process that the Web server is running under can access the UI. For Apache, this is an option in the Services control panel.
Apparently i need to start -> run and type dcomcnfg but that is only for NT/2K/XP.

I am on win98. How can i allow PHP to access the UI?

Mark
Post Reply