pdf-to-png-converter
Version:
Node.js utility to convert PDF file/buffer pages to PNG files/buffers with no native dependencies.
21 lines (20 loc) • 1.2 kB
TypeScript
import { PdfToPngOptions, PngPageOutput } from './types';
/**
* Converts a PDF file to PNG images, one per page.
*
* @param pdfFile - The PDF file to convert. Can be a file path (string) or an ArrayBufferLike.
* @param props - Optional configuration options for the conversion process.
* @returns A promise that resolves to an array of `PngPageOutput` objects, each representing a PNG image of a PDF page.
*
* @remarks
* - If `pdfFile` is a string, it is treated as a file path and read from disk.
* - The `props.pagesToProcess` option allows specifying which pages to convert (1-based indices).
* - The `props.viewportScale` option controls the rendering scale of the PDF pages.
* - The `props.outputFileMaskFunc` option allows customizing the output file name for each page.
* - If `props.outputFolder` is provided, the PNG files are saved to the specified folder.
* - The function processes pages in parallel for efficiency.
* - All resources are cleaned up after processing.
*
* @throws Will throw if the PDF file cannot be read or processed.
*/
export declare function pdfToPng(pdfFile: string | ArrayBufferLike | Buffer, props?: PdfToPngOptions): Promise<PngPageOutput[]>;