UNPKG

chromiumly

Version:

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

153 lines (152 loc) 7.53 kB
import { PathLikeOrReadStream, PdfFormat, Metadata, PdfEngineStamp, PdfEngineWatermark } from '../common'; import { DownloadFrom, WebhookOptions } from '../common/types'; import { EncryptOptions, Bookmarks, MergeOptions, SplitEngineOptions } 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, webhook, flatten, watermark, stamp, rotate }: MergeOptions & { files: PathLikeOrReadStream[]; }): 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, webhook }: { files: PathLikeOrReadStream[]; pdfa?: PdfFormat; pdfUA?: boolean; downloadFrom?: DownloadFrom; webhook?: WebhookOptions; }): 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, webhook, watermark, stamp, rotate }: SplitEngineOptions): 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[], webhook?: WebhookOptions): Promise<Buffer>; /** * Rotates pages of one or more PDF files using the configured PDF engine. * * @param options.files - PDF files to rotate * @param options.angle - Rotation angle in degrees (90, 180, or 270) * @param options.pages - Optional page ranges (e.g. '1-3', '5'); omit for all pages */ static rotate({ files, angle, pages, webhook }: { files: PathLikeOrReadStream[]; angle: 90 | 180 | 270; pages?: string; webhook?: WebhookOptions; }): 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[], webhook?: WebhookOptions): 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, webhook }: { files: PathLikeOrReadStream[]; metadata: Metadata; webhook?: WebhookOptions; }): Promise<Buffer>; static readBookmarks(files: PathLikeOrReadStream[], webhook?: WebhookOptions): Promise<Buffer>; static writeBookmarks({ files, bookmarks, webhook }: { files: PathLikeOrReadStream[]; bookmarks: Bookmarks; webhook?: WebhookOptions; }): 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, webhook }: { files: PathLikeOrReadStream[]; options: EncryptOptions; webhook?: WebhookOptions; }): Promise<Buffer>; /** * Watermarks one or more PDF files using the configured PDF engine. * * @param options.files - PDF files to watermark * @param options.watermark - Watermark configuration (source, expression, pages, options, file) */ static watermark({ files, watermark, webhook }: { files: PathLikeOrReadStream[]; watermark: PdfEngineWatermark; webhook?: WebhookOptions; }): Promise<Buffer>; /** * Stamps one or more PDF files using the configured PDF engine. * * @param options.files - PDF files to stamp * @param options.stamp - Stamp configuration (source, expression, pages, options, file) */ static stamp({ files, stamp, webhook }: { files: PathLikeOrReadStream[]; stamp: PdfEngineStamp; webhook?: WebhookOptions; }): Promise<Buffer>; /** * Embeds attachment files into the given PDFs. * * @param {Object} options - Options for the embed operation. * @param {PathLikeOrReadStream[]} options.files - PDFs to embed into. * @param {PathLikeOrReadStream[]} options.embeds - Files to attach inside the PDF. * @param {WebhookOptions} [options.webhook] - Optional webhook delivery. * @returns {Promise<Buffer>} PDF bytes with embedded files. */ static embed({ files, embeds, webhook }: { files: PathLikeOrReadStream[]; embeds: PathLikeOrReadStream[]; webhook?: WebhookOptions; }): 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>; }