All Projects → rumax → React Native Pdfview

rumax / React Native Pdfview

Licence: mit
📚 PDF viewer for React Native

Programming Languages

javascript
184084 projects - #8 most used programming language
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to React Native Pdfview

Pdfvuer
A PDF viewer for Vue using Mozilla's PDF.js
Stars: ✭ 443 (+123.74%)
Mutual labels:  hacktoberfest, pdf, pdf-viewer
Ng2 Pdf Viewer
📄 PDF Viewer Component for Angular 5+
Stars: ✭ 997 (+403.54%)
Mutual labels:  pdf, pdf-viewer
Buka
Buka is a modern software that helps you manage your ebook at ease.
Stars: ✭ 896 (+352.53%)
Mutual labels:  pdf, pdf-viewer
React Promise
a react.js hook for general promise in typescript
Stars: ✭ 90 (-54.55%)
Mutual labels:  hacktoberfest, react-component
Images To Pdf
An app to convert images to PDF file!
Stars: ✭ 602 (+204.04%)
Mutual labels:  hacktoberfest, pdf
Backslide
💦 CLI tool for making HTML presentations with Remark.js using Markdown
Stars: ✭ 679 (+242.93%)
Mutual labels:  hacktoberfest, pdf
Flutter plugin pdf viewer
A flutter plugin for handling PDF files. Works on both Android & iOS
Stars: ✭ 81 (-59.09%)
Mutual labels:  pdf, pdf-viewer
React Pdf
Display PDFs in your React app as easily as if they were images.
Stars: ✭ 5,320 (+2586.87%)
Mutual labels:  pdf, pdf-viewer
Vue Pdf
vue.js pdf viewer
Stars: ✭ 1,700 (+758.59%)
Mutual labels:  pdf, pdf-viewer
Geeksforgeeksscrapper
Scrapes g4g and creates PDF
Stars: ✭ 124 (-37.37%)
Mutual labels:  hacktoberfest, pdf
Pdfview Android
Small Android library to show PDF files
Stars: ✭ 132 (-33.33%)
Mutual labels:  pdf, pdf-viewer
React Pdf Js
A React component to wrap PDF.js
Stars: ✭ 489 (+146.97%)
Mutual labels:  pdf, pdf-viewer
Laravel Dompdf
A DOMPDF Wrapper for Laravel
Stars: ✭ 4,978 (+2414.14%)
Mutual labels:  hacktoberfest, pdf
Sumatrapdf
SumatraPDF reader
Stars: ✭ 7,462 (+3668.69%)
Mutual labels:  pdf, pdf-viewer
Pdf2htmlex
Convert PDF to HTML without losing text or format.
Stars: ✭ 472 (+138.38%)
Mutual labels:  pdf, pdf-viewer
Jfbview
PDF and image viewer for the Linux framebuffer.
Stars: ✭ 78 (-60.61%)
Mutual labels:  pdf, pdf-viewer
Openpdf
OpenPDF is a free Java library for creating and editing PDF files with a LGPL and MPL open source license. OpenPDF is based on a fork of iText. We welcome contributions from other developers. Please feel free to submit pull-requests and bugreports to this GitHub repository. ⛺
Stars: ✭ 2,174 (+997.98%)
Mutual labels:  hacktoberfest, pdf
React Pdf Highlighter
Set of React components for PDF annotation
Stars: ✭ 448 (+126.26%)
Mutual labels:  pdf, pdf-viewer
Qpdf
PDF viewer widget for Qt
Stars: ✭ 111 (-43.94%)
Mutual labels:  pdf, pdf-viewer
Educative.io Downloader
📖 This tool is to download course from educative.io for offline usage. It uses your login credentials and download the course.
Stars: ✭ 139 (-29.8%)
Mutual labels:  hacktoberfest, pdf

react-native-view-pdf

Codacy Badge npm npm version CircleCI codecov PRs Welcome

Library for displaying PDF documents in react-native

  • android - uses Android PdfViewer. Targets minSdkVersion 21 (required by setClipToOutline) and above.. By default stable version 2.8.2 is used. It's also possible to override it and use 3.1.0-beta.1 (this version allows to handle links, etc. and will be used when Android PdfViewer stable version is released). To change the version, define it in your build file:
buildscript {
  ext {
    ...
    pdfViewer = "3.1.0-beta.1"
  }
  ...
}
  • ios - uses WKWebView. Targets iOS9.0 and above

  • zero NPM dependencies

Getting started

$ npm install react-native-view-pdf --save

Linking

From RN 0.60 there is no need to link - Native Modules are now Autolinked

Mostly automatic installation

$ react-native link

If it doesn't work follow the official react native documentation

Using CocoaPods

In your Xcode project directory open Podfile and add the following line:

pod 'RNPDF', :path => '../node_modules/react-native-view-pdf'

And install:

pod install

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.rumax.reactnative.pdfviewer.PDFViewPackage; to the imports at the top of the file
  • Add new PDFViewPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-view-pdf'
    project(':react-native-view-pdf').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-view-pdf/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
    compile project(':react-native-view-pdf')
    
Note for Android

The Android project tries to retrieve the following properties:

  • compileSdkVersion
  • buildToolsVersion
  • minSdkVersion
  • targetSdkVersion

from the ext object if you have one defined in your Android's project root (you can read more about it here). If not, it falls back to its current versions (check the gradle file for additional information).

Windows

ReactWindows

N/A

Demo

Android iOS
Android iOS

Quick Start

// With Flow type annotations (https://flow.org/)
import PDFView from 'react-native-view-pdf';
// Without Flow type annotations
// import PDFView from 'react-native-view-pdf/lib/index';

const resources = {
  file: Platform.OS === 'ios' ? 'downloadedDocument.pdf' : '/sdcard/Download/downloadedDocument.pdf',
  url: 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
  base64: 'JVBERi0xLjMKJcfs...',
};

export default class App extends React.Component {
  render() {
    const resourceType = 'url';

    return (
      <View style={{ flex: 1 }}>
        {/* Some Controls to change PDF resource */}
        <PDFView
          fadeInDuration={250.0}
          style={{ flex: 1 }}
          resource={resources[resourceType]}
          resourceType={resourceType}
          onLoad={() => console.log(`PDF rendered from ${resourceType}`)}
          onError={(error) => console.log('Cannot render PDF', error)}
        />
      </View>
    );
  }
}

Use the demo project to:

  • Test the component on both android and iOS
  • Render PDF using URL, BASE64 data or local file
  • Handle error state

Props

Name Android iOS Description
resource A resource to render. It's possible to render PDF from file, url or base64
resourceType Should correspond to resource and can be: file, url or base64
fileFrom iOS ONLY: In case if resourceType is set to file, there are different way to search for it on iOS file system. Currently documentsDirectory, libraryDirectory, tempDirectory and bundle are supported.
onLoad Callback that is triggered when loading is completed
onError Callback that is triggered when loading has failed. And error is provided as a function parameter
style A style
fadeInDuration Fade in duration (in ms, defaults to 0.0) to smoothly fade the webview into view when pdf loading is completed
enableAnnotations Android ONLY: Boolean to enable Android view annotations (default is false).
urlProps Extended properties for url type that allows to specify HTTP Method, HTTP headers and HTTP body
onPageChanged Callback that is invoked when page is changed. Provides active page and total pages information
onScrolled Callback that is invoked when PDF is scrolled. Provides offset value in a range between 0 and 1. Currently only 0 and 1 are supported.

Methods

reload

Allows to reload the PDF document. This can be useful in such cases as network issues, document is expired, etc. To reload the document you will need a ref to the component:

...

render() {
  return (
    <PDFView
      ...
      ref={(ref) => this._pdfRed = ref} />
  );
}

And trigger it by calling reloadPDF:

reloadPDF = async () => {
  const pdfRef = this._pdfRef;

  if (!pdfRef) {
    return;
  }

  try {
    await pdfRef.reload();
  } catch (err) {
    console.err(err.message);
  }
}

Or check the demo project which also includes this functionality.

Development tips

On android for the file type it is required to request permissions to read/write. You can get more information in PermissionsAndroid section from react native or Request App Permissions from android documentation. Demo project provides an example how to implement it using Java, check the MainActivity.java and AndroidManifest.xml files.

Before trying file type in demo project, open sdcard/Download folder in Device File Explorer and store some downloadedDocument.pdf document that you want to render.

On iOS, when using resource file you can specify where to look for the file with fileFrom. If you do not pass any value, the component will lookup in two places. First, it will attempt to locate the file in the Bundle. If it cannot locate it there, it will search the Documents directory. For more information on the iOS filesystem access at runtime of an application please refer the official documentation. Note here that the resource will always need to be a relative path from the Documents directory for example and also do NOT put the scheme in the path (so no file://.....).

You can find an example of both usage of the Bundle and Documents directory for rendering a pdf from file on iOS in the demo project.

In demo project you can also run the simple server to serve PDF file. To do this navigate to demo/utils/ and start the server node server.js. (Do not forget to set proper IP adress of the server in demo/App.js)

License

MIT

Authors

Other information

    -keep class com.shockwave.**
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].