npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@uzimandias/react-native-pdf-to-image

v0.1.0

Published

Render PDF pages to images (PNG/JPEG/WebP) in React Native — fast, native, and memory-safe. New Architecture (TurboModule).

Readme

react-native-pdf-to-image

Render PDF pages to images (PNG / JPEG / WebP) in React Native. Native, fast, and memory-safe — pages are rasterized one at a time and freed as they go, so even large documents stay flat on memory.

  • 📄 Convert all pages, a single page, or an inclusive page range
  • 🖼️ PNG, JPEG, and WebP (WebP is Android-only; iOS falls back to PNG)
  • 📐 Size by scale, dpi, or a maxWidth / maxHeight cap (aspect preserved)
  • 💾 Return file URIs, base64, or both
  • 🔒 Encrypted / password-protected PDFs
  • 🔎 Cheap getPdfInfo() — page count, per-page size, and encryption status without rasterizing
  • ⚡️ Built on the New Architecture (TurboModules)

Requirements

  • React Native New Architecture enabled (TurboModules)
  • iOS 15+ (uses PDFKit / Core Graphics)
  • Android API 24+ (uses PdfRenderer). Password-protected PDFs require API 35+.

Installation

npm install @uzimandias/react-native-pdf-to-image
# or
yarn add @uzimandias/react-native-pdf-to-image

iOS

cd ios && pod install

No extra setup on Android — autolinking handles it.

Quick start

import { convert } from '@uzimandias/react-native-pdf-to-image';

const pages = await convert('file:///path/to/document.pdf', {
  format: 'jpeg',
  scale: 2, // 144 DPI
});

// pages[0] => { uri, page, width, height, format }

Render the result with a plain <Image>:

import { Image } from 'react-native';

<Image source={{ uri: pages[0].uri }} style={{ width: 200, height: 280 }} />;

Note: source must be a local file:// path the native module can read. If your PDF comes from a document picker or a remote URL, copy it into the app's cache/documents directory first, then pass that path.

API

getPdfInfo(source, password?) => Promise<PdfInfo>

Read page count, per-page size (in points), and encryption status without rasterizing anything. Use it to lay out a viewer before rendering.

const info = await getPdfInfo('file:///doc.pdf');
// { pageCount: 12, isEncrypted: false, pages: [{ width: 595, height: 842 }, ...] }

convert(source, options?) => Promise<PageImage[]>

Render every page.

const pages = await convert('file:///doc.pdf', { format: 'png', dpi: 300 });

convertPage(source, page, options?) => Promise<PageImage>

Render a single page (0-based).

const cover = await convertPage('file:///doc.pdf', 0, { scale: 3 });

convertPages(source, from, to, options?) => Promise<PageImage[]>

Render an inclusive range [from, to] (0-based).

const firstThree = await convertPages('file:///doc.pdf', 0, 2);

Options (ConvertOptions)

| Option | Type | Default | Description | | ----------------- | ------------------------------ | ------------- | ----------------------------------------------------------------------------------------- | | scale | number | 2 | Render resolution as a multiple of native 72 DPI. 1 = 72, 2 = 144, ~4.16 = 300 DPI. | | dpi | number | — | Target DPI. Overrides scale when set. | | maxWidth | number | — | Cap output width in px; page scaled to fit (aspect preserved). | | maxHeight | number | — | Cap output height in px; page scaled to fit (aspect preserved). | | format | 'png' \| 'jpeg' \| 'webp' | 'jpeg' | Output encoding. webp is Android-only; iOS falls back to png. | | quality | number (0–1) | 0.9 | JPEG / WebP only (PNG is lossless). | | backgroundColor | string | '#FFFFFF' | Solid fill behind transparent content; used by JPEG. | | password | string | — | Password for encrypted PDFs (iOS + Android API 35+). | | outputDir | string | app cache dir | Directory to write images into. | | filePrefix | string | source name | Filename prefix for generated files. | | output | 'file' \| 'base64' \| 'both' | 'file' | file → write image, return uri. base64 → no disk write. both → file and base64. |

Returned shape (PageImage)

interface PageImage {
  uri: string; // file:// URI to the written image ('' when output is 'base64')
  page: number; // 0-based page index
  width: number; // pixel width of the rendered image
  height: number; // pixel height of the rendered image
  format: 'png' | 'jpeg' | 'webp';
  base64?: string; // present only when output is 'base64' or 'both'
}

Using base64 output? Build a data URI for <Image>:

const page = await convertPage('file:///doc.pdf', 0, { output: 'base64' });
const uri = `data:image/${page.format};base64,${page.base64}`;

Error handling

Rejected promises carry a stable error.code. Match against PdfToImageErrorCode:

import { convert, PdfToImageErrorCode } from '@uzimandias/react-native-pdf-to-image';

try {
  await convert('file:///doc.pdf', { password: 'wrong' });
} catch (e) {
  if (e.code === PdfToImageErrorCode.WRONG_PASSWORD) {
    // prompt for the right password
  }
}

| Code | Meaning | | --------------------- | --------------------------------------------- | | E_FILE_NOT_FOUND | Source path does not exist. | | E_INVALID_PDF | File is not a readable PDF. | | E_PASSWORD_REQUIRED | PDF is encrypted and no password was given. | | E_WRONG_PASSWORD | Supplied password was rejected. | | E_PAGE_OUT_OF_RANGE | Requested page index is outside the document. | | E_RENDER_FAILED | A page failed to rasterize. | | E_IO | Failed to write the output file. |

Example app

A full example exercising every option lives in example/:

yarn
yarn example ios     # or: yarn example android

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT © Usman salim


Made with create-react-native-library