您好,欢迎访问一九零五行业门户网

php office如何转 pdf

php office转pdf的方法:首先配置“php.ini”,并重启环境;然后配置office组件服务;接着在控制台根节点下,找到【wps……】,右键设置属性;最后编写程序实现转换即可。
推荐:《php视频教程》
一、配置环境
(1)配置php.ini
添加:extension=php_com_dotnet.dll
com.allow_dcom = true  // 去掉号,改为true
重启环境
(2) 安装:wps 专业版,或者 microsoft  office 2010
(microsoft office 2007 需要安装加载项:microsoft save as pdf) 
(3)配置office组件服务
        按 win+r 快捷键进入运行菜单,输入 dcomcnfg 
        找到:     [组件服务] —— [计算机]—— [我的电脑] —— [dcom配置] ——【wps……】或[microsoft wrord 97-2003文档]
        如果没找到【wps……】或(microsoft wrord 97-2003文档):
        按 win+r 快捷键进入运行菜单
        输入:mmc -32
        [文件]——[添加或删除管理单元]——[组件服务](从可用管理单元,添加到所选管理单元,点击:确定)
        添加完以后,在控制台根节点下,找到【wps……】或[microsoft wrord 97-2003文档],右键设置属性,设置“标识”为:交互式用户(还有安全里面的设置 可以看其他文章的设置)
注:我开始 选择交互式用户  : 会出现 我登录远程服务器一切正常,如果退出远程服务器实例化组件就报错,最后选择了 下列用户,填写了管理员用户和密码才正常可用.
二、编写程序
<?phpword2pdf(); function word2pdf(){ $filenamedoc = dirname(__file__)."/index.docx"; $filenamepdf = dirname(__file__)."/index.pdf"; $dd = $word = new com("kwps.application") or die ("could not initialise object."); // 或者 $dd = $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 // 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'); } echo 'ok';}?>
if(!function_exists('read_pdf')) { function read_pdf($file) { if(strtolower(substr(strrchr($file,'.'),1)) != 'pdf') { echo '文件格式不对.'; return; } if(!file_exists($file)) { echo '文件不存在'; return; } header('content-type: application/pdf'); header('filename='.$file); readfile($file); }}
以上就是php office如何转 pdf的详细内容。
其它类似信息

推荐信息