WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Class to convert any document, that can be read by MS Word, to another format supported by Word.
Categories : PHP Classes, PHP, Windows 2000, Microsoft Word, WinNT Click here to Update Your Picture
alain samoun
Date : Nov 17th 2001
Grade : 1 of 5 (graded 2 times)
Viewed : 5362
File : wordconvert.zip
Images : No Images for this code example.
Search : More code by alain samoun
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

wordconvert.php
<?php
/* Class to convert any document, that can be read by MS Word, to another format supported by Word.
     * © Alain M. Samoun 10/2001.
     * alain@samoun.com
     * Gnu GPL code (see www.fsf.org for more information).
    * Tested on win98 + Apache1.3  PHP 4.8 dev as CGI  - Word 2000
    * This file should be saved in the PHP's include directory.
    *If you try to use COM in XP/win2k or NT, you need to set-up permissions to the application
     with the program >DCOMCNFG.EXE :
    Run DCOMCNFG.exe, select the application and add permissions in Security:
    - Custom Access Permissions: “Allow”
    Then Edit / Add
    - the “IUSR_<servername>” user access to the object.- The user account to run the application:
     “The interactive user”
    And close.
    * Usage:
    <?php
        require ("wordconvert.php");
        new wordconvert($filename,$convert_to,$visible);
    ?>
    * Conversion time example: Convert a 33 pages rtf document (133KB) to an htm file (268KB)
      in 6 sec. (300MHz processor). Not a speed daemon, but will work for small files on servers
      with low hits number (Intranet...).
*/
   
class wordconvert
   
{

           
/* variables */
   
var $filename;    # Original File name with optional path.
            # If no path provided, will be looked for in My Documents.
   
var $convert_to=0;      # Extension (as a string) or number (See Doc on SaveAs method below),
            # doc extension is the default.
   
var $visible=0;    # 0=Hidden, 1= Visible, hidden is the default.
   
          /* Constructor */

             
function wordconvert($filename,$convert_to=0,$visible=0)
               {
               
                   
$filename_pathsubstr($filename,0,-4);
           
            if (
is_string ($convert_to))
            {
               
$convert_to= strtolower($convert_to);
           
                 switch (
$convert_to)
                 {
                         case
"doc":
                             
$convert_to=0;
                             Break;
                         case
"dot":
                             
$convert_to=1;
                             Break;
                         case
"txt":
                             
$convert_to=2;
                             Break;
                         case
"rtf":
                             
$convert_to=6;
                             Break;
                         case
"htm":
                             
$convert_to=8;
                             Break;
                         case
"html":
                             
$convert_to=8;
                             Break;
                         case
"asc":
                             
$convert_to=9;
                             Break;
                         case
"wri":
                             
$convert_to=13;
                             Break;
                         case
"wps":
                             
$convert_to=28;
                             Break;
                         default:
                             
$convert_to=0;
                     }
                 }
           
# Instantiate MSWord
             
$word=new COM("Word.Application") or die("Cannot start MS Word");
     
             
$word->visible = $visible ;
     
           
#Open the original file in word.
           
$word->Documents->Open($filename)or die("Cannot find file to convert");

/*
Doc on SaveAs method:
expression.SaveAs(FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter)
Only the two first parameters are supported in this class.
File save format number to use ( WdSaveFormat prop. ):
  wdFormatDocument = 0;  wdFormatTemplate = 1;  wdFormatText = 2;  wdFormatTextLineBreaks = 3;
  wdFormatDOSText = 4;  wdFormatDOSTextLineBreaks = 5;  wdFormatRTF = 6;  wdFormatUnicodeText = 7;
  Extensions=number: doc=0,dot =1,txt=2,htm=8,asc=9,wri=13,doc(word perfect DOS)=24,wps(works)=28
*/


            #Save the new file
           
$word->ActiveDocument->SaveAs($filename_path,$convert_to);

/*
Doc on quit method:
expression.Quit(SaveChanges, Format, RouteDocument)
*/

           
$word->quit(0); #0: Quit without saving
            # print "done!";
   
       
}#End of func
   
   
}#End of class
?>


Usage
<?php
/*
* Example using the wordconvert Class to convert an RTF document to the html format.
* (c) Alain M. Samoun 10/2001.
* alain@samoun.com
* Gnu GPL code (see www.fsf.org for more information).
* Tested on win98 + Apache PHP 4.8 dev, PHP4.6 - Word 2000
*If you try to use COM in win2k/XP or NT, you >need to set-up permissions to the application
with the program >DCOMCNFG.EXE :
    Run DCOMCNFG.exe, select the application and add permissions in Security:
    - Custom Access Permissions: “Allow”
    Then Edit / Add
    - the “IUSR_<servername>” user access to the object.- The user account to run the application:
     “The interactive user”
    And close.
* To run this example: Put the wordconvert.php file in your include directory,
    Edit the filename  and the extension that you wish below.
then call this file from your server or run it from the command line.
   



*/

       
require ("wordconvert.php"); # The class file wordconvert.php should be saved on the PHP include directory
   
    # Change as you wish with your own values:
       
$filename="c:/windows/desktop/my briefcase/manual.doc";
       
$ext = "htm"; # - will convert rtf file above to htm file
       
$ext = 8;       # Same as above. See class info for Extension <-> Number correspondence.
       
$vis= 1; # =1Word will be visible, =0 to hide it
   
    # Run the script with the above values   
   
new wordconvert($filename,$ext,$vis); #Do the trick
   

   
print "done!";
?>



file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
News management class
Categories : PHP, PHP Classes, Beginner Guides
The class to check load time of your script VERY usefull for relatively slow applications, but not only..
Categories : PHP, PHP Classes, Debugging
Expose - PHP template engine, supports server and client-sided caching,a plugin system, multiple languages, template script language is based on PHP itself.
Categories : PHP, PHP Classes, Templates, Complete Programs
Simple Template Class/Example
Categories : PHP, Templates, PHP Classes
RSS parser. Parses RSS into an array. Quick and nasty but does the job. No checking is done for correct Tags, only correct XML. PHP4 needed to display result (uses print_r).
Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS)
MS Word Mail Merge Automation (COM)
Categories : PHP, PHP Classes, COM
Very minimal templating engine
Categories : PHP, PHP Classes, Templates
ElfReader: An ELF (Executable and Linking Format) header information in PHP. Shows how to use the UNPACK function to read data.
Categories : PHP, Linux, PHP Classes
an example of the cyberlib payment class
Categories : PHP, PHP Classes, Ecommerce, Credit Cards
pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes
Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip
Categories : Email, Network, PHP, PHP Classes