Launching a Word-to-PDF Cloud Service on Function Compute

By Du Wan

Charging by the number of calls and dynamic scaling features makes Function Compute an ideal solution for deploying online conversion tools, such as image clipping, webpage-to-image, and text-to-audio tools. These conversion tools are usually implemented with CPP and eventually compiled into binary command tools or DLLs. Because Function Compute is remotely called over HTTP in multi-language runtime environments, it is also suitable for the heterogeneous mode. This document explains how to quickly deploy a Word-to-PDF cloud service based on the fc-libreoffice project.

fc-libreoffice is a NPM with nodejs-based interface encapsulation. It incorporates the built-in and pre-compiled LibreOffice for running Function Compute. LibreOffice is tailored and compressed by using the Brotli algorithm and with a high compression ratio. However, the compression package is 84 MB, exceeding the upper limit (50 MB) of Function Compute. Therefore, in the example, we use Object Storage Service (OSS) to upload the LibreOffice file and download and compress it before running. The following primarily explains how to quickly deploy the LibreOffice cloud service by calling make commands encapsulated in scripts.

Dependent Tools

For MacOS systems, use the following installation method:

For other platforms, install by using NPM.

The command line tool for OSS is ossutil. Download and store the tool in the directory that $PATH points to.

Clone a Project

Under the fc-libreoffice project, a sample project is provided to show how to quickly deploy a project through simple configuration.

Modify the Configuration File

Configure the environment variables in the .env file

Deploy and Verify Functions

Deploy a function. In this step, install dependencies, upload the LibreOffice file to OSS, and deploy the function to Function Compute.

Call the function. Convert the prepared example.docx file to the example.pdf file and upload it to OSS.

Download the example.pdf file from OSS to the current directory. View the conversion result.

The conversion result is as follows. The left figure shows the DOCX source file and the right figure shows the generated PDF file. Both Chinese characters and embedded images were correctly converted.

Conclusion

fc-libreoffice/example is only a sample project. For applications in actual production environments, there is still a lot of room for optimization, including integrity verification of downloaded files, streaming decompression, support for source file import and target file export over HTTP, and warm-up with a time trigger to reduce the cold startup costs. For the make commands in the document, we called some automation steps that are written with the bash script. These steps involve the commonly used methods and techniques for Function Compute. If you are interested in the LibreOffice migration process, check out the article How to Migrate LibreOffice to Function Compute or the source code of fc-libreoffice.

Reference:https://www.alibabacloud.com/blog/launching-a-word-to-pdf-cloud-service-on-function-compute_594593?spm=a2c41.12692415.0.0

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.