หน้า 1 จากทั้งหมด 1

ใช้ php แปลไฟล์ Word .doc เป็น PDF ไฟล์ โดยใช้ lib ของ OpenOffice

โพสต์แล้ว: 01/01/2010 12:55 am
โดย mindphp
ใช้ php แปลไฟล์ Word .doc เป็น PDF ไฟล์ โดยใช้libของ OpenOffice
ส่วนการแปลง ไฟล์อื่นๆ เป็น pdf ได้ทำไว้ที่นี่ลองใช้ดู ครับ
https://www.mindphp.com/modules.php?name=Pdf_Creator
โค้ด

โค้ด: เลือกทั้งหมด

<?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);
?>

ในเครื่องต้องติดตั้ง OpenOffice ไว้ด้วยนะครับ

Re: ใช้ php แปลไฟล์ Word .doc เป็น PDF ไฟล์

โพสต์แล้ว: 04/01/2010 1:03 am
โดย pinatcha
ขอบคุณมากๆๆๆๆ สำหรับ Code นะคะ

:-D

Re: ใช้ php แปลไฟล์ Word .doc เป็น PDF ไฟล์ โดยใช้ lib ของ OpenOffice

โพสต์แล้ว: 28/05/2022 6:16 pm
โดย บุคคลทั่วไป
ขอบคุณคะ ขอเอาไปใช้หน่อย