API reference
The convert() signature, its options, the returned pages and the error codes.
convert(input, options?)
import { convert } from "pdf-raster";
function convert(
input: string | Buffer | Uint8Array | ArrayBuffer,
options?: ConvertOptions,
): Promise<ConvertedPage[]>;Renders the requested pages of a PDF and resolves to one ConvertedPage per
page, in the order of options.pages. It rejects with a PdfToImagesError on
failure.
Input
Prop
Type
Any other value throws INVALID_INPUT.
ConvertOptions
Prop
Type
ConvertedPage
Prop
Type
PdfToImagesError
import { PdfToImagesError } from "pdf-raster";
class PdfToImagesError extends Error {
name: "PdfToImagesError";
code: PdfToImagesErrorCode;
}code is one of:
| Code | Meaning |
|---|---|
INVALID_INPUT | The input is not a path, Buffer, Uint8Array or ArrayBuffer. |
INVALID_OPTIONS | An option is invalid, such as a DPI of 0 or an unknown format, or a page exceeds maxPixels or 65,535 pixels on a side. |
INVALID_PAGE_INDEX | A page index is negative, not an integer, or past the last page. |
INVALID_CROP | The crop rectangle is malformed or extends past the rendered page. |
PASSWORD_ERROR | The PDF is encrypted and the password is missing or wrong. |
MALFORMED_PDF | PDFium could not parse the file. |
PDFIUM_UNAVAILABLE | The native addon or the PDFium library could not load. |
RENDER_ERROR | Rendering or encoding failed after the input passed validation. |
Errors and troubleshooting covers how to handle each one.
Exported types
ConvertInput, ConvertOptions, ConvertedPage, Crop, OutputFormat and
PdfToImagesErrorCode are exported as types from pdf-raster.