Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 24th, 2006, 03:37 AM
Registered User
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Word file to Text File Converter

I am trying to convert a word file in to text file by the following code :


 function wordToText($wordDocPath,$textFilePath)
    { $word = new COM("word.application") or die("Unable to instanciate Word");
        $word->Visible = 0;
        $word->Documents->Open($wordDocPath);
        $numParagraphs = $word->ActiveDocument->Paragraphs->Count;
        $paraString = '';
        for($i = 1; $i <= $numParagraphs; $i++)
        {
        $paraString .= $word->ActiveDocument->Paragraphs[$i];
        }
        $word->Quit();
        $handle = fopen($textFilePath, 'w');
        fwrite($handle, $paraString);
        fclose($handle);
    }
      wordToText('d:\test\test1.doc', 'docdump.txt');
                print 'Conversion Complete.';

If I run this code in localhost it is working but, when I upload this file in to server the folloowing error is coming :

Fatal error: Class 'COM' not found in /home/destiny/public_html/weblink/word.php on line 4


 
Old July 25th, 2006, 07:29 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Given that the error message references your home directory as "/home/destiny", it looks like a Linux box. You cannot instantiate Windows COM components on Linux. Perhaps there are other PHP libraries out there that parse Office files natively rather than relying on a Windows application... but I'm not sure what they're called. (Java has one called Apache POI.)

Jon Emerson
http://www.jonemerson.net/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Text file and convert to Binary file VB.net sjlsysprg1 Pro VB.NET 2002/2003 4 June 29th, 2007 06:53 AM
how to copy text in a word file on the clipboard donrafeal Word VBA 3 February 1st, 2007 12:32 AM
Word wrap in XSL that transforms to a text file suri_1811 XSLT 1 November 15th, 2006 03:59 PM
save a PDF file as text file through VB. NET kvenkatu VB.NET 0 April 6th, 2006 12:15 PM
Need symbol file converter mouse C++ Programming 0 July 25th, 2003 06:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.