thinkphp实现word转化为pdf格式


直接贴代码:

请求路径:http://根目录?m=Jwgl&c=excellentCourse&a=word2pdf&filename=590fcfa23dd81.docx

//将doc文件转化为pdf
function word2pdf()
{
//获取文件名
$filename = I("filename");
$filenamedoc = "F:/wamp/www/tessqlsrv/Uploads/excellentCourse/".I("filename");
$filenamepdf = "F:/wamp/".substr($filename,0,13).".pdf";
// $lastfnamedoc = "F:/wamp/www/tessqlsrv/Uploads/excellentCourse/590e9f53c6923.docx";
// $lastfnamepdf = "F:/wamp/590e9f53c6923.pdf";
$word = new \COM("Word.Application") or die ("Could not initialise Object.");
// set it to 1 to see the MS Word window (the actual opening of the document)
$word->Visible = 0;
// recommend to set to 0, disables alerts like "Do you want MS Word to be the default .. etc"
$word->DisplayAlerts = 0;
// open the word 2007-2013 document
// $word->Documents->Open('3.docx');
// $wordname='D:/www/fa/3.doc';
$word->Documents->Open($filenamedoc);
// save it as word 2003
// $word->ActiveDocument->SaveAs('4.doc');
// convert word 2007-2013 to PDF
// $pdfname='D:/www/fa/3.pdf';
//判断要生成的文件名是否存在
if(file_exists($filenamepdf)) {
//存在就删除
unlink ($filenamepdf);
}
$word->ActiveDocument->ExportAsFixedFormat($filenamepdf, 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);
// quit the Word process
$word->Quit(false);
// clean up
unset($word);
if(!function_exists('read_pdf')) {
header('Content-type: application/pdf');
header('filename='.$filenamepdf);
readfile($filenamepdf);
read_pdf('Python_study.pdf');
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM