pdf-raster

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:

CodeMeaning
INVALID_INPUTThe input is not a path, Buffer, Uint8Array or ArrayBuffer.
INVALID_OPTIONSAn 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_INDEXA page index is negative, not an integer, or past the last page.
INVALID_CROPThe crop rectangle is malformed or extends past the rendered page.
PASSWORD_ERRORThe PDF is encrypted and the password is missing or wrong.
MALFORMED_PDFPDFium could not parse the file.
PDFIUM_UNAVAILABLEThe native addon or the PDFium library could not load.
RENDER_ERRORRendering 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.

On this page