https://github.com/songsterq/react-native-pdf-thumbnail
react native module for generating thumbnail for PDF files
https://github.com/songsterq/react-native-pdf-thumbnail
pdf react-native
Last synced: about 1 year ago
JSON representation
react native module for generating thumbnail for PDF files
- Host: GitHub
- URL: https://github.com/songsterq/react-native-pdf-thumbnail
- Owner: songsterq
- License: mit
- Created: 2020-07-06T06:29:37.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-11T12:47:24.000Z (about 2 years ago)
- Last Synced: 2025-04-30T19:08:36.987Z (about 1 year ago)
- Topics: pdf, react-native
- Language: Java
- Homepage:
- Size: 2.83 MB
- Stars: 45
- Watchers: 1
- Forks: 22
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# react-native-pdf-thumbnail
A react native module for generating thumbnail for PDF files.
A wrapper for:
- PDFKit on iOS (requires iOS 11+)
- PdfRenderer on Android (requires API level 21 - LOLLIPOP)
No other JavaScript or native dependencies.
Note: This module **does not** work in Expo.
## Installation
```sh
npm install react-native-pdf-thumbnail
```
## Usage
```js
import PdfThumbnail from "react-native-pdf-thumbnail";
// For iOS, the filePath can be a file URL.
// For Android, the filePath can be either a content URI, a file URI or an absolute path.
const filePath = 'file:///mnt/sdcard/myDocument.pdf';
const page = 0;
// The thumbnail image is stored in caches directory, file uri is returned.
// Image dimensions are also available to help you display it correctly.
const { uri, width, height } = await PdfThumbnail.generate(filePath, page);
// Generate thumbnails for all pages, returning an array of the object above.
const results = await PdfThumbnail.generateAllPages(filePath);
// Default compression quality is 80, you can optionally specify a quality between 0 and 100.
const { uri, width, height } = await PdfThumbnail.generate(filePath, page, 95);
const results = await PdfThumbnail.generateAllPages(filePath, 90);
```
## Demo
The example app contains a document picker, it generates and displays a thumbnail for the selected PDF file.
To run it:
```sh
yarn
yarn example ios
yarn example android
```
iOS | Android
------- | ---
 | 
## Contributing
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
## License
MIT