使用Gotenberg和Google Cloud将.docx转换为.pdf [英] Converting .docx to .pdf using Gotenberg and Google Cloud
问题描述
在这里,我偶然发现将.docx转换为.pdf.那里唯一可行的解决方案似乎是 Gotenberg ,它是Docker支持的无状态API,并且
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.
要使用JS客户端,我们需要定义Gotenberg的Docker驱动的地址:
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
)
我既不是JS向导,也不是客户端或后端向导,所以我想问你们:我如何(如果可能的话)使用Google Cloud解决方案来实现它?
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?
现在,我正在使用Firebase Cloud Functions生成.docx(与客户端相同),并且希望能够将它们转换为.pdf(客户端和后端).这是可以实现的吗?这是可扩展的吗?
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?
推荐答案
您可以使用 Firebase云函数(使用基础的Cloud Function)与 nodejs运行时一个>.但是,如果您不打算运行Firebase应用,我建议您仅使用Cloud Function.
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.
您可以查看此快速入门,以进行介绍.之后,您可以尝试部署自己的函数,在 package.json
文件中指定您的 gotenberg-js-client
依赖项.
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.
您唯一需要决定的就是函数如何访问文件.我建议将pdf文件存储在 Cloud Storage 存储桶中,并使用
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.
这篇关于使用Gotenberg和Google Cloud将.docx转换为.pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!