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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@khanhdh1303/rn-pdf-page-viewer

v1.0.2

Published

Minimalist PDF viewer for React Native

Downloads

5

Readme

react-native-pdf-page-viewer

This library fork by react-native-pdf-light, we add more function: getBase64Image, isLocked.

PDF viewer for React Native. Implemented with platform native render functions for smallest deploy size impact, and restricted feature set to simplify integration with larger systems.

Includes prefabricated full document viewer based on FlatList and a single page render component to use as a building block for your own fully custom viewer.

Uses android.graphics.pdf.PdfRenderer on Android and CGPDFDocument on iOS. Unlike many native components in the wild, react-native-pdf-page-viewer provides full implementation of React Native shadow nodes. This simplifies UI development, since the component actually knows its own dimensions.

Installation

npm install @khanhdh1303/rn-pdf-page-viewer

If iOS build fails with Undefined symbol: __swift_FORCE_LOAD_..., add an empty .swift file to the xcode project.

Usage

import { Pdf, PdfUtil } from '@khanhdh1303/rn-pdf-page-viewer';

PdfUtil.getPageCount(source).then(console.log);

<Pdf source={source} />

If creating your own custom viewer, import can be optimized to:

import { PdfView } from '@khanhdh1303/rn-pdf-page-viewer';

<PdfView page={page} source={source} />

<Pdf ... /> Display a pdf.

Props:

  • onError: (error: Error) => void
    • Optional: Callback to handle errors.
  • onLoadComplete: (numberOfPages: number) => void
    • Optional: Callback to handle pdf load completion.
    • Passed the page count of the loaded pdf.
  • onMeasurePages: (measurements: { itemHeight: number, offset: number }[]) => void
    • Optional: Callback to receive layout details of all pages.
  • shrinkToFit: 'never' | 'portrait' | 'landscape' | 'always'
    • Optional: Size pages such that each page can be displayed without cutoff.
    • Applies when device is in the specified orientation.
  • source: string
    • Document to display.

The following props are forwarded to the underlying FlatList component:

  • initialScrollIndex
  • ListEmptyComponent
  • onMomentumScrollBegin
  • onMomentumScrollEnd
  • onScroll
  • onScrollBeginDrag
  • onScrollEndDrag
  • refreshControl
  • scrollEventThrottle

Methods:

  • scrollToIndex(index: number): void
    • Scroll to the specified page (0-indexed).
  • scrollToOffset(offset: number): void
    • Scroll to the specified offset.

<PdfView ... /> Single page of a pdf.

Props:

  • page: number
    • Page (0-indexed) of document to display.
  • resizeMode: 'contain' | 'fitWidth'
    • Optional: How pdf page should be scaled to fit in view dimensions.
  • source: string
    • Document to display.
  • style: ViewStyle
    • Optional: View stylesheet.

PdfUtil Utility functions.

PdfUtil.getPageCount(source: string): Promise<number>

  • Get the number of pages of a pdf.

PdfUtil.getPageSizes(source: string): Promise<{ height: number; width: number }[]>

  • Get the dimensions of every page.

PdfUtil.getBase64Image(source: string, page: number): Promise<string>

  • Get image(base64) of every page

PdfUtil.isLocked(source: string): Promise<boolean>

  • Check pdf is protected with pwd (JUST FOR IOS), on android use try-catch, it's throw error if can't open pdf has pwd

Known Issues

On Android API level < 26 when directly rendering pages with PdfView at a non-default aspect ratio (e.g. setting both width and height of the view such that the view's aspect ratio does not match the pdf page's aspect ratio) if a page in the pdf is cropped or rotated, the page may render in the wrong position. This is due to a bug in the native android.graphics.pdf.PdfRenderer. (If you are aware of a fix, pull requests welcome.)

Alternatives

Contributing

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

License

MIT