Php: convert MS Word to PDF

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
pqres
Forum Newbie
Posts: 4
Joined: Thu Sep 29, 2005 12:08 am

Php: convert MS Word to PDF

Post by pqres »

Dear All,

I need to convert a MS Word document to pdf format in my PHP
program. Is there library that I can make use of? I'd appreciate
if anyone could give a sample about it.

Thanks.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

http://www.pdfonline.com has a program you can buy. or try this code:
but firs you have to install the free program http://download.openoffice.org/2.0.2/index.html on your server

Code: Select all

<?php
set_time_limit(0);
function MakePropertyValue($name,$value,$osm){
$oStruct = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStruct;
}
function word2pdf($doc_url, $output_url){
//Invoke the OpenOffice.org service manager
$osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");
//Set the application to remain hidden to avoid flashing the document onscreen
$args = array(MakePropertyValue("Hidden",true,$osm));
//Launch the desktop
$oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");
//Load the .doc file, and pass in the "Hidden" property from above
$oWriterDoc = $oDesktop->loadComponentFromURL($doc_url,"_blank", 0, $args);
//Set up the arguments for the PDF output
$export_args = array(MakePropertyValue("FilterName","writer_pdf_Export",$osm));
//Write out the PDF
$oWriterDoc->storeToURL($output_url,$export_args);
$oWriterDoc->close(true);
}
$output_dir = "C:/dev/openofficeintegration/docconverter/";
$doc_file = "C:/dev/openofficeintegration/docconverter/DpmR5Reqv1.20.doc";
$pdf_file = "DpmR5Reqv1.20.pdf";
$output_file = $output_dir . $pdf_file;
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
word2pdf($doc_file,$output_file);
?>
pqres
Forum Newbie
Posts: 4
Joined: Thu Sep 29, 2005 12:08 am

Post by pqres »

Thanks for the infor. I contacted the pdfonline for the API, but was told that easyPDF SDK supports Windows, but not Unix. Any other alternative, since I am using an Unix hosting service?

Thanks!
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

first get something that converts docs to html:
http://www.topshareware.com/Word2html-P ... -18008.htm

then something to convert html to pdf:
http://www.digitaljunkies.ca/dompdf/
Post Reply