在PHP Web环境中将复杂DOCX转换为PDF

I am working on a PHP web application which programatically generates some DOCX files. I want these files to be converted to PDF, but their layout is so complex that not any PHP-PDF generator library (domPDF, TCPDF, etc.) works well. They result in a poorly formatted PDF in each case.

In this situation, I have decided to let Google Drive do the conversion. For this, I have to:

  1. Upload the DOCX files to GDrive
  2. And then export them in PDF...

I have seen all of the GDrive API documentation, but it is very poorly documented. I only want to execute one single PHP script which:

  • Uploads the file to GDrive
  • Downloads its exported PDF version
  • Lets the PDF be downloaded when the script is finished...

I am searching for the optimal way to achieve this behaviour... (with or without GDrive, since the LibreOffice/Openffice CLI command is not an option because I am on a web hosting and I can't install any software...).

Have you considered using a file conversion service to do this for you ?

For complete transparency I work for Zamzar (an online file conversion website), we have recently released a developer API - https://developers.zamzar.com/ that would allow you to convert your DOCX files to PDF with little or no loss of formatting.

This would then eradicate your need to convert your file(s) using the Google Drive API. Check out our fairly extensive docs here - https://developers.zamzar.com/docs.