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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ratley/expo-pdf

v0.1.13

Published

A native PDF viewer that uses PDFKit on iOS and PdfRenderer/Pdfium on Android

Readme

expo-pdf

An Expo module that provides a fast, reliable PDF viewer for iOS and Android with a clean React Native API. It supports imperative page navigation, paging events, basic zoom controls, password‑protected files, and helpful utilities like sharing and page thumbnails.

Install

  • Add dependency: npm install expo-pdf
  • iOS: run npx pod-install

PdfView

Render a PDF from a URL, file path, or file:// URI.

Props (cross‑platform)

  • source: string — http(s) URL, local file path, file:// URL, or bundle resource name.
  • page?: number — 1‑based controlled page index.
  • initialPage?: number — 1‑based one‑shot initial page.
  • initialPageIndex?: number — 0‑based one‑shot initial page (advanced; prefer initialPage).
  • enableDoubleTapZoom?: boolean — toggle double‑tap zoom. Default true.
  • spacing?: number — inter‑page spacing.
  • scrollEnabled?: boolean — enable/disable scrolling. Default true.
  • password?: string — supply a password to unlock encrypted PDFs.
  • nativePasswordPrompt?: boolean — Android only. Show a native password dialog when a locked PDF is detected. Defaults to true. Set to false to handle passwords in JS via onPasswordRequired and the password prop.

Events

  • onLoad({ nativeEvent: { source, pageCount } })
  • onError({ nativeEvent: { message } })
  • onPageChanged({ nativeEvent: { page, pageCount? } })
  • onPasswordRequired()
  • onScaleChanged({ nativeEvent: { scale } }) — iOS only.

Ref methods

  • next() — go to next page
  • prev() — go to previous page
  • goToPage(page: number) — 1‑based
  • getPage(): number
  • getPageCount(): number

Basic usage

import { PdfView } from "expo-pdf";

export function Doc({ uri }: { uri: string }) {
  return (
    <PdfView
      source={uri}
      spacing={8}
      enableDoubleTapZoom
      onLoad={(e) => console.log("pages", e.nativeEvent.pageCount)}
    />
  );
}

Disable next/prev at ends

import { PdfView, type PdfViewRef } from "expo-pdf";
import { useRef, useState } from "react";

export function Paged({ uri }: { uri: string }) {
  const ref = useRef<PdfViewRef | null>(null);
  const [page, setPage] = useState(0);
  const [count, setCount] = useState(0);
  const isFirst = page <= 1;
  const isLast = count > 0 && page >= count;

  return (
    <>
      <PdfView
        ref={ref}
        source={uri}
        onLoad={(e) => setCount(e.nativeEvent.pageCount)}
        onPageChanged={(e) => {
          setPage(e.nativeEvent.page);
          if (typeof e.nativeEvent.pageCount === "number") setCount(e.nativeEvent.pageCount);
        }}
      />
      <Button disabled={isFirst} onPress={() => ref.current?.prev?.()} title="Prev" />
      <Button disabled={isLast} onPress={() => ref.current?.next?.()} title="Next" />
    </>
  );
}

Utilities

  • shareAsync(source: string | { source: string }) — present native share sheet for the given source.
  • getPageThumbnailAsync({ source, page?, width, height, scale? }) — returns a PNG data URL.
  • clearCacheAsync() — clears disk cache used for remote PDFs.

Passwords

  • iOS

    • When a locked document is detected and no working password is provided, the view emits onPasswordRequired and keeps content hidden until unlocked.
    • Provide the password via the password prop. On success, the view emits onLoad({ pageCount }) and resumes normal events. Wrong passwords emit onError({ message: "Invalid password" }).
  • Android

    • Default behavior shows a native password dialog when a locked PDF is detected. Disable with nativePasswordPrompt={false} to handle the flow in JS using onPasswordRequired + password.
    • Wrong passwords emit onError({ message: "Invalid password" }) in JS‑driven mode.
  • Minimal usage

import { PdfView } from "expo-pdf";
import { useState } from "react";

export function ProtectedDoc({ uri, suppliedPassword }: { uri: string; suppliedPassword?: string }) {
  const [waitingForPassword, setWaitingForPassword] = useState(false);
  return (
    <PdfView
      source={uri}
      password={suppliedPassword}
      onPasswordRequired={() => setWaitingForPassword(true)}
      onLoad={() => setWaitingForPassword(false)}
    />
  );
}

Limitations

  • getPageThumbnailAsync does not unlock password‑protected PDFs on Android; thumbnails for locked PDFs will fail.

Example layout

See example/components/PDFViewerLayout.tsx for a headless layout that wires the props above and demonstrates page state, sharing, and edge‑button disabling.

Platform notes

  • iOS uses PDFKit.
  • Android uses PdfRenderer for thumbnails and AndroidPdfViewer for on‑screen rendering (marain87 fork).

Contributing

PRs welcome! To develop locally with the example app:

  1. Clone and build the module
  • git clone https://github.com/ratley/expo-pdf && cd expo-pdf
  • bun install
  • bun run build
  1. Run the example app (autolinks this module)
  • iOS: cd example && bunx expo run:ios
  • Android: cd example && bunx expo run:android

Notes

  • After native iOS changes, re-running bunx expo run:ios from the example directory is sufficient. It will handle pod installation.
  • You can also use bun run ios|android from the example if you prefer the package scripts.