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

PHP Result Center PHP Result Center เป็นหมวด ที่ไว้รวบรวม โปรแกรม Code php Javascript CSS CMS

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41232
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

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

โพสต์ที่ยังไม่ได้อ่าน โดย 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 ไว้ด้วยนะครับ
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
pinatcha
PHP Jr. Member
PHP Jr. Member
โพสต์: 13
ลงทะเบียนเมื่อ: 04/01/2010 1:00 am

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

โพสต์ที่ยังไม่ได้อ่าน โดย pinatcha »

ขอบคุณมากๆๆๆๆ สำหรับ Code นะคะ

:-D
บุคคลทั่วไป

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

โพสต์ที่ยังไม่ได้อ่าน โดย บุคคลทั่วไป »

ขอบคุณคะ ขอเอาไปใช้หน่อย
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 51