UNPKG

chromiumly

Version:

A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.

54 lines 3.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LibreOffice = void 0; const tslib_1 = require("tslib"); const main_config_1 = require("../main.config"); const common_1 = require("../common"); const libre_office_utils_1 = require("./utils/libre-office.utils"); /** * Class representing a LibreOffice for various operations such as merging and conversion. */ class LibreOffice { /** * Converts various document formats to PDF. * * @param {Object} options - Options for the conversion operation. * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the files to be converted to PDF. * @param {PageProperties} [options.properties] - Page properties for the conversion. * @param {pdfa} [options.pdfFormat] - PDF format options. * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output. * @param {boolean} [options.merge] - Indicates whether to merge the resulting PDFs. * @param {Metadata} [options.metadata] - Metadata to be included in the converted PDF. * @param {boolean} [options.losslessImageCompression] - Indicates whether to use lossless image compression. * @param {boolean} [options.reduceImageResolution] - Indicates whether to reduce image resolution. * @param {number} [options.quality] - Quality of the JPG export. * @param {75 | 150 | 300 | 600 | 1200} [options.maxImageResolution] - Maximum image resolution for the converted PDF. * @param {Split} [options.split] - Split the PDF into multiple files. * @param {boolean} [options.flatten] - Flatten the PDF document. * * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a buffer */ static convert(_a) { return tslib_1.__awaiter(this, arguments, void 0, function* ({ files, properties, pdfa, pdfUA, merge, metadata, losslessImageCompression, reduceImageResolution, quality, maxImageResolution, split, flatten }) { const data = new FormData(); yield libre_office_utils_1.LibreOfficeUtils.addFiles(files, data); yield libre_office_utils_1.LibreOfficeUtils.customize(data, { properties, merge, pdfa, pdfUA, metadata, losslessImageCompression, reduceImageResolution, quality, maxImageResolution, split, flatten }); const endpoint = `${main_config_1.Chromiumly.getGotenbergEndpoint()}/${main_config_1.Chromiumly.LIBRE_OFFICE_PATH}/${main_config_1.Chromiumly.LIBRE_OFFICE_ROUTES.convert}`; return common_1.GotenbergUtils.fetch(endpoint, data, main_config_1.Chromiumly.getGotenbergApiBasicAuthUsername(), main_config_1.Chromiumly.getGotenbergApiBasicAuthPassword(), main_config_1.Chromiumly.getCustomHttpHeaders()); }); } } exports.LibreOffice = LibreOffice; //# sourceMappingURL=libre-office.js.map