Search code examples
javascriptnode.jsgoogle-cloud-platformgoogle-cloud-functionsgotenberg

Converting .docx to .pdf using Gotenberg and Google Cloud


As many here I stumbled across converting .docx to .pdf. The only reasonable solution out there seems to be Gotenberg which is a Docker-powered stateless API and Gotenberg js client which allows to interact with Gotenberg much easier through JS interface.

To use JS client we need to define Gotenberg's Docker-powered address:

import { pipe, gotenberg, convert, html, please } from 'gotenberg-js-client'

const toPDF = pipe(
  gotenberg('http://localhost:3000'), <--- here
  convert,
  html,
  please
)

I'm no wizard of JS nor client-side nor backend so I want to ask you guys: how (if possible) I could implement it using Google Cloud solutions?

Now I'm using Firebase Cloud Functions to generate .docx (the same I do on the client-side) and I want to be able to convert them to .pdf (both client and backend). Is this achievable? Is this scalable?


Solution

  • You can use a Firebase Cloud Functions (which uses an underlying Cloud Function) with the nodejs runtime. But if you are not planning to run a Firebase App I would recommend you to use just a Cloud Function.

    You can take a look at this quickstart to get an introduction. After that you can try to deploy your own function specifying yourgotenberg-js-client dependency in the package.json file.

    The only thing you need to decide is how will the function access to the file. I recommend to store the pdf files in a Cloud Storage bucket and use the nodejs Cloud Storage client library to access them from within your Cloud Function.