简体   繁体   English

使用 Gotenberg 和 Google Cloud 将.docx 转换为.pdf

[英]Converting .docx to .pdf using Gotenberg and Google Cloud

As many here I stumbled across converting.docx to.pdf.我在这里偶然发现了 convert.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.唯一合理的解决方案似乎是Gotenberg ,它是一个 Docker 驱动的无状态 API 和Gotenberg js 客户端,它允许通过 JS 接口更轻松地与 Gotenberg 交互。

To use JS client we need to define Gotenberg's Docker-powered address:要使用 JS 客户端,我们需要定义 Gotenberg 的 Docker-powered 地址:

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?我不是 JS 的向导,也不是客户端或后端,所以我想问你们:我如何(如果可能)使用 Google Cloud 解决方案来实现它?

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).现在我正在使用 Firebase Cloud Functions 来生成.docx(我在客户端也这样做),我希望能够将它们转换为.pdf(客户端和后端)。 Is this achievable?这是可以实现的吗? Is this scalable?这是可扩展的吗?

You can use a Firebase Cloud Functions (which uses an underlying Cloud Function) with thenodejs runtime .您可以将Firebase Cloud Functions (它使用底层 Cloud Functions)与nodejs runtime一起使用。 But if you are not planning to run a Firebase App I would recommend you to use just a Cloud Function.但是,如果您不打算运行 Firebase 应用程序,我建议您只使用云 Function。

You can take a look at this quickstart to get an introduction.您可以查看此快速入门以获得介绍。 After that you can try to deploy your own function specifying your gotenberg-js-client dependency in the package.json file.之后,您可以尝试部署自己的 function,在package.json文件中指定您的gotenberg-js-client依赖项。

The only thing you need to decide is how will the function access to the file.您唯一需要决定的是 function 将如何访问该文件。 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.我建议将 pdf 文件存储在Cloud Storage 存储桶中,并使用nodejs Cloud Storage 客户端库从您的 Cloud Function 中访问它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM