Search code examples
pdfms-wordgoogle-drive-apigoogle-oauth

Using Google Cloud or Drive to Programatically Convert Word to PDF


Candidates use my PHP application to upload their CV in either Word or PDF format. I want to convert the Word documents (doc or docx) to PDF. I have tried using on-server solutions (PHP libraries), but can not find one that is reliable enough so I am now exploring Google solutions.

It seems that the Drive API has just what I need. I can:

  • upload a Word document and request conversion to Google Doc.
  • export the doc as a PDF
  • delete the doc

The problem is that (as far as I can see), the only way I can access the Drive API is via OAuth 2, which is quite an overhead in the case of simple server-to-server access. I would prefer to use a simple API key.

As far as I can see, if I want to use an API key, then I need to sign up for a Google Service Account, which again seems like quite an overhead. (I only want to convert some files, right?).

Is there a straightforward way to achieve my goal (using Google resources)? Or are the two options above my only choices?


Solution

  • Your use case is a perfect fit for a Service Account. It's not really much of an overhead, say 10 minutes to set up the account and a couple of hours to write the auth code. If you would rather use a regular account, check out How do I authorise an app (web or installed) without user intervention? which has step by step instructions and sample code.