详情页

帝国cms实现上传word文档生成html并保存图片

时间:2023年05月22日

编辑:佚名

插件功能: 后台编辑界面,点击上传word文档,上传后解析word文档为html返回到编辑器。word文档包含的图片自动保存到服务器。
安装方法:
 [帝国cms插件]上传word文档生成html并保存图片
第一步,首先服务器安装免费开源的LibreOffice
安装记录:
#安装文件
yum -y install libreoffice
#安装中文包
yum -y install libreoffice-langpack-zh-Han*
#安装HOME目录
 /usr/lib64/libreoffice
#检查安装版本
soffice --version
#测试转换命令
soffice --headless --convert-to html /opt/123.doc --outdir /opt
插件安装
找到/etc/sudoers文件
查找
## Allow root to run any commands anywhere
在rootALL=(ALL) ALL后面添加
www     ALL=(ALL)   NOPASSWD: ALL
宝塔面板php  禁用函数
shell_exec  删除
#跳坑记录
tmp为空文件夹,插件运行时要用,请勿删除。
第二步,解压本插件到/e/extend/下。
第三步,配置其中的config.php文件
<?php
//这是执行转换的主程序位置
return "sudo soffice ";
//word中的图片,如何保存?1 保存为图片文件;2 base64保存在html中
$imgWhere=1;
//根据您的需求,对word转到的html格式化
function formathtml($content){
   // here is your code
   // line-height: 100%
   $content=str_replace('line-height: 100%','line-height: 150%',$content);
   $content = preg_replace_callback(
        '| ([0-9]{1,2})pt|',
        function ($matches) {
            return ' '.(2*$matches[1]).'px';
        },
        $content
    );
   return $content;
}
第四步,可以使用了,以下为效果图。
相关文章
猜你需要