UNPKG

chromiumly

Version:

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

115 lines (114 loc) 5.71 kB
import { PathLikeOrReadStream, PdfFormat, Metadata } from '../common'; import { DownloadFrom, Split } from '../common/types'; import { EncryptOptions } from './interfaces/pdf-engines.types'; /** * Class uses PDF engines for various operations such as merging and conversion. */ export declare class PDFEngines { /** * Merges multiple PDF files into a single PDF document. * * @param {Object} options - Options for the merge operation. * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the PDF files to be merged. * @param {PdfFormat} [options.pdfa] - PDF format options. * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output. * @param {Metadata} [options.metadata] - Metadata to be written. * @param {DownloadFrom} [options.downloadFrom] - Download a file from a URL. It must return a Content-Disposition header with a filename parameter. * @param {boolean} [options.flatten] - Flatten the PDF document. * * @returns {Promise<Buffer>} A Promise resolving to the merged PDF content as a buffer */ static merge({ files, pdfa, pdfUA, metadata, downloadFrom, flatten }: { files: PathLikeOrReadStream[]; pdfa?: PdfFormat; pdfUA?: boolean; metadata?: Metadata; downloadFrom?: DownloadFrom; flatten?: boolean; }): Promise<Buffer>; /** * 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 {PdfFormat} [options.pdfa] - PDF format options. * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output. * @param {DownloadFrom} [options.downloadFrom] - Download a file from a URL. It must return a Content-Disposition header with a filename parameter. * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a buffer */ static convert({ files, pdfa, pdfUA, downloadFrom }: { files: PathLikeOrReadStream[]; pdfa?: PdfFormat; pdfUA?: boolean; downloadFrom?: DownloadFrom; }): Promise<Buffer>; /** * Splits a PDF file into multiple PDF files. * * @param {Object} options - Options for the split operation. * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the PDF files to be split. * @param {Split} options.options - Split configuration specifying mode ('pages' or 'intervals'), span, and unify options. * @returns {Promise<Buffer>} A Promise resolving to the split PDF content as a buffer */ static split({ files, options }: { files: PathLikeOrReadStream[]; options: Split; }): Promise<Buffer>; /** * Flattens a PDF file. * * @param {PathLikeOrReadStream[]} files - An array of PathLikes or ReadStreams to the PDF files to be flattened. * @returns {Promise<Buffer>} A Promise resolving to the flattened PDF content as a buffer */ static flatten(files: PathLikeOrReadStream[]): Promise<Buffer>; /** * Reads metadata from the provided files. * * @param {PathLikeOrReadStream[]} files An array of PathLikes or ReadStreams to the PDF files. * @returns {Promise<Buffer>} A Promise resolving to the metadata buffer. */ static readMetadata(files: PathLikeOrReadStream[]): Promise<Buffer>; /** * Writes metadata to the provided PDF files. * * @param {PathLikeOrReadStream[]} files - An array of PathLikes or ReadStreams to the PDF files. * @param {Metadata} metadata - Metadata to be written. * @returns {Promise<Buffer>} A Promise that resolves to the PDF file containing metadata as a buffer. */ static writeMetadata({ files, metadata }: { files: PathLikeOrReadStream[]; metadata: Metadata; }): Promise<Buffer>; /** * Encrypts a PDF file. * * @param {Object} options - Options for the encrypt operation. * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the PDF files to be encrypted. * @param {EncryptOptions} options.options - Encryption configuration specifying userPassword (required) and ownerPassword (optional). * @returns {Promise<Buffer>} A Promise resolving to the encrypted PDF content as a buffer */ static encrypt({ files, options }: { files: PathLikeOrReadStream[]; options: EncryptOptions; }): Promise<Buffer>; /** * Embeds files into PDF files. * * @param {Object} options - Options for the embed operation. * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the PDF files to embed files into. * @param {PathLikeOrReadStream[]} options.embeds - An array of PathLikes or ReadStreams to the files to embed in the PDF. * @returns {Promise<Buffer>} A Promise resolving to the PDF content with embedded files as a buffer */ static embed({ files, embeds }: { files: PathLikeOrReadStream[]; embeds: PathLikeOrReadStream[]; }): Promise<Buffer>; /** * Generates a PDF file from a buffer and saves it to the "__generated__" directory. * * @param {string} filename - The filename for the generated PDF. * @param {Buffer} buffer - The PDF content as a buffer * @returns {Promise<void>} A Promise that resolves once the file is generated and saved. */ static generate(filename: string, buffer: Buffer): Promise<void>; }