Hazem Khairy Mohamed
Hazem Khairy Mohamed

Reputation: 73

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.

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.

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.

I am using PHPWord to generate the Docx files from templates.

Attempts:

a) I tried to use PHPWord to convert the Docx file to an HTML file but it generates a blank file.

b) I tried to use COM with OpenOffice but the following error appeared:

HTTP Error 500.0 - Internal Server Error. C:\php\php-cgi.exe - The FastCGI process exceeded configured request timeout

c) I tried to use COM with Word.application, but I received Access denied.

Note: I am a beginner at PHP.

Upvotes: 1

Views: 914

Answers (1)

Andrii Tarykin
Andrii Tarykin

Reputation: 628

You have a couple of choices:

  1. Go to GitHub and try to find a package (written in PHP) that converts your need.
  2. Write a little service to communicate another binary that can do this job. You can use something like this or this.
  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.

Upvotes: 1

Related Questions