php将word转换为pdf

word转pdf(通过命令进行转)

    1. 服务器上安装LIbreOffice
      使用 yum 安装 LibreOffice:
      sudo yum update -y
      安装 LibreOffice:
      sudo yum install libreoffice-headless libreoffice-writer libreoffice-calc libreoffice-impress -y
      查看安装成功:
      soffice --version
    1. 直接上代码:
php 复制代码
    public function convertDocxToPdf()
    {
        $docxPath = ROOT_PATH."template/template.docx";
        // 确保 LibreOffice 在系统路径中可用
        $pdfFilePath = ROOT_PATH.'pdf/output.pdf';
        $command = "soffice --headless --convert-to pdf $docxPath --outdir " . escapeshellarg(dirname($pdfFilePath));
        exec($command, $output, $returnVar);

        if ($returnVar !== 0) {
            throw new \Exception("Error converting to PDF: " . implode("\n", $output));
        }

        return $pdfFilePath;
    }
相关推荐
桃花键神2 小时前
Undetectable接入亮数据代理IP深度测评:高效、稳定、适配性极强的海外多账号运营利器
网络协议·tcp/ip·php
catchadmin3 小时前
PHP 8.5 #[\NoDiscard] 揪出“忽略返回值“的 Bug
php
Rover Ramble4 小时前
提取大型非扫描pdf文件的表格数据
pdf
2501_907136827 小时前
电子礼簿系统-红白喜事记账工具,PDF/Execl导出
pdf·软件需求
oMcLin8 小时前
如何在 Debian 11 上实现基于 BGP 路由的动态负载均衡,提升跨地域数据中心的连接稳定性
debian·php·负载均衡
oMcLin9 小时前
如何在RHEL 9上配置并优化Kubernetes 1.23高可用集群,提升大规模容器化应用的自动化部署与管理?
kubernetes·自动化·php
ben9518chen9 小时前
Linux文件系统基础
linux·服务器·php
王五周八9 小时前
html转化为base64编码的pdf文件
前端·pdf·html
电商API&Tina21 小时前
京东 API 数据采集接口接入与行业分析
运维·服务器·网络·数据库·django·php