For the complete documentation index, see llms.txt. This page is also available as Markdown.

View a PDF document in React Native

This guide will help you to view a document using the Apryse React Native SDK.

Preparation

Usage-Github

If you installed through GitHub, replace App.js with the code below.

If you set your path variable to point to a local storage file, then the PermissionsAndroid component is required to ensure that storage permission is properly granted.

Within this example there are several sections of commented out code that work together to handle storage permissions.

Below the example are the types of file paths that are native to iOS or Android and accepted by the DocumentView component.

import React, { Component } from "react";
import {
  Platform,
  StyleSheet,
  Text,
  View,
  PermissionsAndroid,
  BackHandler,
  NativeModules,
  Alert,
} from "react-native";

import { DocumentView, RNPdftron } from "react-native-pdftron";

type Props = {};
export default class App extends Component<Props> {
  constructor(props) {
    super(props);

    RNPdftron.enableJavaScript(true);
  }

  onLeadingNavButtonPressed = () => {
    console.log("leading nav button pressed");
    if (Platform.OS === "ios") {
      Alert.alert(
        "App",
        "onLeadingNavButtonPressed",
        [{ text: "OK", onPress: () => console.log("OK Pressed") }],
        { cancelable: true }
      );
    } else {
      BackHandler.exitApp();
    }
  };

  render() {

    const path =
      "https://pdftron.s3.amazonaws.com/downloads/pl/PDFTRON_mobile_about.pdf";

    return (
      <DocumentView
        document={path}
        showLeadingNavButton={true}
        leadingNavButtonIcon={
          Platform.OS === "ios"
            ? "ic_close_black_24px.png"
            : "ic_arrow_back_white_24dp"
        }
        onLeadingNavButtonPressed={this.onLeadingNavButtonPressed}
      />
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#F5FCFF",
  },
});

Usage-NPM

If you installed through NPM package, Replace App.js with the code below.

If you set your path variable to point to a local storage file, then the PermissionsAndroid component is required to ensure that storage permission is properly granted.

Within this example there are several sections of commented out code that work together to handle storage permissions.

Below the example are the types of file paths that are native to iOS or Android and accepted by the DocumentView component.

if you are using the npm package use this instead

To open a document from other sources, change the document={path} line to:

Run

In the root project directory (`/MyApp`), run `react-native run-ios`. Your application should look like this:

Next step

GuidesSamplesAPI docs

You can view the source code for this project here.

Last updated

Was this helpful?