简体   繁体   English

PHP 将 docx 文件转换为 pdf

[英]PHP convert docx file to pdf

I am using PHP as a backend end, I generate a Docx file on the backend and I want to send it to the frontend to make the user print it directly without downloading it.我使用 PHP 作为后端,我在后端生成一个Docx文件,我想将它发送到前端,让用户直接打印它而不下载它。

So I wanted to convert the Docx file to PDF and put it on the server so I can send its link to the frontend to make the user able to view it and print it.所以我想将Docx文件转换为PDF并将其放在服务器上,这样我就可以将其链接发送到前端,以便用户能够查看并打印它。

But I am not able to convert from Docx to pdf , can anyone tell me an easy way to convert from Docx to pdf , or if anyone has an alternative way to do the whole process.但我无法从Docx转换为pdf ,谁能告诉我一种从Docx转换为pdf的简单方法,或者如果有人有另一种方法来完成整个过程。

I am using PHPWord to generate the Docx files from templates.我正在使用PHPWord从模板生成Docx文件。

Attempts:尝试:

a) I tried to use PHPWord to convert the Docx file to an HTML file but it generates a blank file. a) 我尝试使用PHPWordDocx文件转换为HTML文件,但它会生成一个空白文件。

b) I tried to use COM with OpenOffice but the following error appeared: b) 我尝试将COMOpenOffice一起使用,但出现以下错误:

HTTP Error 500.0 - Internal Server Error. HTTP 错误 500.0 - 内部服务器错误。 C:\php\php-cgi.exe - The FastCGI process exceeded configured request timeout C:\php\php-cgi.exe - FastCGI 进程超过了配置的请求超时

c) I tried to use COM with Word.application , but I received Access denied. c) 我尝试将 COM 与Word.application一起使用,但我收到拒绝访问。

Note: I am a beginner at PHP.注意:我是 PHP 的初学者。

You have a couple of choices:你有几个选择:

  1. Go to GitHub and try to find a package (written in PHP) that converts your need. Go 到 GitHub 并尝试找到转换您需要的 package(用 PHP 编写)。
  2. Write a little service to communicate another binary that can do this job.编写一个小服务来与另一个可以完成这项工作的二进制文件通信。 You can use something like this or this .您可以使用类似thisthis的东西。
  3. You can write your own solution but I do not recommend doing it.您可以编写自己的解决方案,但我不建议这样做。

Also, you can check this article and build it on top of Azure serverless.此外,您可以查看这篇文章并将其构建在 Azure 无服务器之上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM