1.2.0 • Published 8 months ago

react-native-pdf-renderer v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

React-Native Pdf Renderer

License MIT npm version npm downloads

⚛ A zoomable, blazing fast, zero dependencies, pure native, typed PDF Renderer for Android and iOS.

It uses PdfRenderer for Android and PdfKit for iOS.

AndroidiOS

Requirements

  • React Native >= 0.60.0
  • iOS >= 11.0
  • Android >= API 19

Install

Install dependency package

yarn add react-native-pdf-renderer

Or

npm i -S react-native-pdf-renderer

Go to the folder your-project/ios and run pod install, and you're done.

Basic usage

There is only one component that you need to use to render the PDF file.

import PdfRendererView from 'react-native-pdf-renderer';

const App = () => {
   return (
      <SafeAreaView style={{flex: 1}}>
         <PdfRendererView
            style={{backgroundColor: 'red'}}
            source="file:///path/to/local/file.pdf"
            distanceBetweenPages={16}
            maxZoom={5}
            onPageChange={(current, total) => {
               console.log(current, total);
            }}
         />
      </SafeAreaView>
   );
}

export default App;

The source prop must point to a file stored inside device memory.

If the file is online, you can use some third part library like expo-file-system, rn-fetch-blob or react-native-blob-util to download and save locally.

For more details, see the Sample Project.

PdfRendererView props

NameValueDefaultDescription
sourcestringPath to a file stored on device.
distanceBetweenPagesnumber16Distance in DPI between pages.
maxZoomnumber5Max zoom scale.
singlePagebooleanfalse(Experimental) Renders only the first page without scroll. (useful for display thumbnail)
onPageChange(current: number, total: number) => voidInvoked on pages scroll.
styleStyleProp<ViewStyle>Styles to be applied to the View

Limitations

Size measuring

The PdfRendererView is flex: 1 by default, so you need to make sure that your parents View are flex: 1 or have a fixed width/height.

Border radius

The borderRadius style is ignored by React Native custom view in Android and crash on iOS. (read more #1)

If you need borderRadius, the best option is to wrap the PdfRendererView in another View.

<View style={{ flex: 1, borderRadius: 24, overflow: 'hidden' }}>
   <PdfRendererView
      // ...
   />
</View>

Contribute

New features, bug fixes and improvements are welcome! For questions and suggestions use the issues.

Donate

Thanks to

This lib is only possible thanks to the community help:

Star History

Star History Chart

License

The MIT License (MIT)

Copyright (c) 2023 Douglas Nassif Roma Junior

See the full license file.

1.2.0

8 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.1.0-beta.2

12 months ago

1.1.0-beta.1

12 months ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago