@cincel.digital/doc-convert-plugin
This package provides a plugin for converting various file types to PDF using LibreOffice on the server. It is designed to be used with the Hapi framework.
Installation
yarn add @cincel.digital/doc-convert-plugin
# or
npm i @cincel.digital/doc-convert-plugin
Usage
const Hapi = require("hapi")(async () => {
const server = await new Hapi.Server({
port: 8000,
})
await server.register({
plugin: require("@cincel.digital/doc-convert-plugin"),
// options: {},
})
})()
Configuration
The plugin accepts the following options:
-
maxFileSize
(optional): Maximum allowed file size in bytes. Default is 5MB. -
endpointUrl
(optional): The URL endpoint for the conversion. Default is "/convert-to-pdf". -
dest
(optional): The destination directory where uploaded files will be stored. Default is "uploads". -
accept
(optional): An object specifying the accepted file types for conversion. Default is a predefined set of file types including images, Microsoft Excel, Microsoft Word, and CSV.
API
The plugin provides a single endpoint for file conversion:
-
POST
{endpointUrl}
: Upload a file and convert it to PDF. The file should be sent as amultipart/form-data
payload with the field namefile
. The response will be the converted PDF file.
Error Handling
The plugin may send the following errors in case of failure:
Error Code | Status | Message |
---|---|---|
ERR_001 | 415 | Unsupported Media Type |
ERR_002 | 500 | LibreOffice is not installed on the server. |
ERR_003 | 422 | The provided file does not conform to the expected format. Please ensure that the 'file' property is a valid Readable stream. |
ERR_004 | 400 | The PDF file cannot be used because it is encrypted. |
ERR_005 | 400 | The PDF file was not generated correctly. |