new COM()实现word转pdf

管理员 发布于 6年前   370

这里我windows+phpstudy+php5.5.38

1.开启COM

 1.jpg

  一:com.allow_dcom = true

  二:[PHP_COM_DOTNET]

         extension=php_com_dotnet.dll

检测是否开启:

1.png

2.word转pdf代码

$filename = '1.doc';  //被转文件名
$filenamedoc = "D:/LightTPD/".'1.doc';  //被转文件绝对路径
$filenamepdf = "D:/LightTPD/".substr($filename,0,13).".pdf"; //转成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($filenamedoc);
// save it as word 2003
// $word->ActiveDocument->SaveAs('4.doc');
// convert word 2007-2013 to 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');
}

  一:

1.png

 二:转成pdf

2.png




请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

该博客于2020-12-7日,后端基于go语言的beego框架开发
前端页面使用Bootstrap可视化布局系统自动生成

是我仿的原来我的TP5框架写的博客,比较粗糙,底下是入口
侯体宗的博客

      订阅博客周刊

文章标签

友情链接

HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群
侯体宗的博客