Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-pdf

Package Overview
Dependencies
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-pdf

A react native PDF view component, support ios and android platform

  • 6.7.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
161K
increased by1.56%
Maintainers
1
Weekly downloads
 
Created

What is react-native-pdf?

The react-native-pdf package is a React Native library that allows you to display PDF documents in your mobile applications. It provides a range of functionalities to handle PDF files, including loading PDFs from various sources, rendering pages, and handling user interactions such as zooming and scrolling.

What are react-native-pdf's main functionalities?

Load PDF from URL

This feature allows you to load a PDF document from a URL and display it within your React Native application. The code sample demonstrates how to load a PDF from a remote URL and handle events such as loading completion, page changes, and errors.

import React from 'react';
import { View, StyleSheet } from 'react-native';
import Pdf from 'react-native-pdf';

const PdfExample = () => {
  const source = { uri: 'http://www.pdf995.com/samples/pdf.pdf', cache: true };
  return (
    <View style={styles.container}>
      <Pdf
        source={source}
        onLoadComplete={(numberOfPages, filePath) => {
          console.log(`Number of pages: ${numberOfPages}`);
        }}
        onPageChanged={(page, numberOfPages) => {
          console.log(`Current page: ${page}`);
        }}
        onError={(error) => {
          console.log(error);
        }}
        style={styles.pdf}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'flex-start',
    alignItems: 'center',
    marginTop: 25,
  },
  pdf: {
    flex: 1,
    width: '100%',
    height: '100%',
  },
});

export default PdfExample;

Load PDF from local file

This feature allows you to load a PDF document from a local file and display it within your React Native application. The code sample demonstrates how to load a PDF from a local file path and handle events such as loading completion, page changes, and errors.

import React from 'react';
import { View, StyleSheet } from 'react-native';
import Pdf from 'react-native-pdf';

const PdfExample = () => {
  const source = require('./path/to/local/file.pdf');
  return (
    <View style={styles.container}>
      <Pdf
        source={source}
        onLoadComplete={(numberOfPages, filePath) => {
          console.log(`Number of pages: ${numberOfPages}`);
        }}
        onPageChanged={(page, numberOfPages) => {
          console.log(`Current page: ${page}`);
        }}
        onError={(error) => {
          console.log(error);
        }}
        style={styles.pdf}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'flex-start',
    alignItems: 'center',
    marginTop: 25,
  },
  pdf: {
    flex: 1,
    width: '100%',
    height: '100%',
  },
});

export default PdfExample;

Zoom and scroll

This feature allows users to zoom in and out of the PDF document and scroll through its pages. The code sample demonstrates how to enable zooming and scrolling functionalities in the PDF viewer.

import React from 'react';
import { View, StyleSheet } from 'react-native';
import Pdf from 'react-native-pdf';

const PdfExample = () => {
  const source = { uri: 'http://www.pdf995.com/samples/pdf.pdf', cache: true };
  return (
    <View style={styles.container}>
      <Pdf
        source={source}
        onLoadComplete={(numberOfPages, filePath) => {
          console.log(`Number of pages: ${numberOfPages}`);
        }}
        onPageChanged={(page, numberOfPages) => {
          console.log(`Current page: ${page}`);
        }}
        onError={(error) => {
          console.log(error);
        }}
        style={styles.pdf}
        scale={1.0}
        minScale={1.0}
        maxScale={3.0}
        horizontal={false}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'flex-start',
    alignItems: 'center',
    marginTop: 25,
  },
  pdf: {
    flex: 1,
    width: '100%',
    height: '100%',
  },
});

export default PdfExample;

Other packages similar to react-native-pdf

Keywords

FAQs

Package last updated on 20 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc