惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
B
Blog
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
爱范儿
爱范儿
博客园_首页
博客园 - 聂微东
量子位
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
Netflix TechBlog - Medium
F
Fortinet All Blogs
The Cloudflare Blog
T
Tailwind CSS Blog
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
腾讯CDC

Inside Nutrient

A guide to the invisible work behind documents Introducing Nutrient Documents for Salesforce: Native document generation and signing Document AI vs. traditional OCR: Choosing between OCR, AI, and hybrid pipelines PDF SDK compliance and security evaluation checklist for enterprise teams (2026) Invariant Corp replaces paper processes with Nutrient Workflow and scales without limits What is process mapping? A complete guide Nutrient vs. Conga Composer for Salesforce document generation (2026) Document routing: How to automate document distribution The CTO’s AI playbook: Why accountability architecture beats orchestration Compliance workflow automation: Why built-in compliance is table stakes Workflow diagrams: Examples, symbols, and how to build one that actually runs Digital forms: Replace paper forms with automated workflows Approval workflow software: How to automate approvals Why document-centric automation is different The CEO’s AI playbook: Why decision architecture beats model selection Nutrient SDK product updates for Q1 2026 PDF redaction verification: How to prove sensitive data is permanently removed What is a VPAT? The complete guide to accessibility conformance reports What is PDF/UA? The accessible PDF standard explained Salesforce eSignatures: Generate, sign, and track documents in one flow Online document viewer: Options, tradeoffs, and how to embed one Document viewer for web apps: React, Vue, Angular (2026) Best document viewers in 2026: A buyer’s guide How to edit a PDF in Python: Add text, images, and annotations Nutrient advances Workflow platform with agentic AI for enterprise-grade speed and consistency in document-heavy operations How to create a Salesforce quote template from opportunity data The business case for accessibility: Five ways it drives enterprise value Python PDF library comparison (2026): 7 libraries for developers Why your AI agent hallucinates PDF table data PDF.js limitations: When to upgrade to a commercial PDF SDK
Generate PDF documents in React Native
Erhard Brand · 2024-06-11 · via Inside Nutrient

Table of contents

    Generate PDF documents in React Native

    Summary

    Learn how to generate custom PDF documents in React Native using Nutrient’s commercial library for comprehensive PDF functionality. This tutorial demonstrates creating blank PDFs, combining pages from existing documents, and converting HTML to PDF using the Processor component. Discover how to integrate advanced PDF capabilities, including annotations, editing, forms, digital signatures, and UI customization into your React Native applications.

    In this post, you’ll learn how to generate custom PDF documents in your React Native application using Nutrient. This process can be useful for creating a PDF from HTML or selecting certain pages from an existing PDF document.

    Nutrient React Native library

    Nutrient offers a commercial React Native library for viewing, generating, annotating, and editing PDFs. You can use it to quickly add PDF functionality to your React Native applications.

    It offers a variety of additional features and capabilities, including:

    You can view our demo to see what Nutrient is capable of and determine how you can use it for your project.

    Getting started

    These next sections will walk you through how to get started generating PDFs in React Native.

    Dependencies

    The following dependencies are necessary:

    The Nutrient React Native dependency is installed directly from our GitHub repository. To install the Nutrient React Native dependency, run yarn @nutrient-sdk/react-native in your project directory or npm install @nutrient-sdk/react-native if you’re using npm.

    Creating a new project

    This tutorial will focus on React Native iOS, but Android can also be used. Some additional configuration, which can be found in our React Native getting started guide, is required.

    In your macOS environment, open your terminal of choice. In the terminal, change your working directory to a suitable location to create your new React Native app.

    1. Create a new React Native project by running the following command:

    npx react-native init NutrientDemo

    1. Change your working directory to the newly created project:
    1. Add the Nutrient plugin:

    yarn add @nutrient-sdk/react-native

    1. Add react-native-fs to the project:
    1. Install all the project dependencies:
    1. Open your project’s Podfile in a text editor to update the platform to iOS 15:
    1. In your Podfile, update the deployment target version to iOS 15:

    platform :ios, min_ios_version_supported

    platform :ios, '15.0'

    1. Change the location of the current working directory to the ios folder:
    1. Install the CocoaPods dependencies:
    1. Open your project’s Workspace in XCode:

    open NutrientDemo.xcworkspace

    1. Change View controller-based status bar appearance to YES in your project’s Info.plist:

    Running the Project

    Once you’ve followed the steps above, run your application to confirm the project is correctly set up thus far. From the root of the NutrientDemo project, run:

    If you see the React Native welcome screen, you’re ready to proceed!

    The code supplied in the following sections can be added to your application’s App.tsx file inside the render function, prior to returning the PSPDFKitView component that will display your PDF documents.

    Generating new PDF documents in React Native

    When generating a new PDF document, the required configuration properties will depend on which operation you’re performing.

    Generating a blank PDF

    To generate a blank PDF document, use the BlankPDFConfiguration object to set up your configuration:

    import { BlankPDFConfiguration } from "@nutrient-sdk/react-native";

    const Processor = NativeModules.RNProcessor;

    const configuration: BlankPDFConfiguration = {

    filePath: `file:///${RNFS.TemporaryDirectoryPath}/newDocument.pdf`,

    width: 595,

    height: 842,

    override: true,

    };

    const { fileURL } = await Processor.generateBlankPDF(configuration);

    Generating a PDF from existing documents

    It might be useful to select specific pages from an existing PDF document or specific pages from different PDF documents and combine them into a new document. Use the DocumentPDFConfiguration object to set up your configuration:

    import RNFS from "react-native-fs";

    import { DocumentPDFConfiguration } from "@nutrient-sdk/react-native";

    const Processor = NativeModules.RNProcessor;

    const configuration: DocumentPDFConfiguration = {

    filePath: `file:///${RNFS.TemporaryDirectoryPath}/newDocument.pdf`,

    documents: [

    {

    documentPath: "path/to/document1.pdf",

    pageIndex: 5,

    },

    {

    documentPath: "path/to/document2.pdf",

    pageIndex: 8,

    },

    ],

    override: true,

    };

    const { fileURL } = await Processor.generatePDFFromDocuments(configuration);

    Generating a PDF from HTML

    You can also convert an HTML string or URL to a PDF document using the Processor component. Use the GeneratePDFConfiguration object to set up your configuration:

    import RNFS from "react-native-fs";

    import { GeneratePDFConfiguration } from "@nutrient-sdk/react-native";

    const Processor = NativeModules.RNProcessor;

    const configuration: GeneratePDFConfiguration = {

    filePath: `file:///${RNFS.TemporaryDirectoryPath}/newDocument.pdf`,

    override: true,

    };

    const htmlString = `

    <!DOCTYPE html>

    <html>

    <title>HTML Tutorial</title>

    <body>

    <h1>This is a heading</h1>

    <p>This is a paragraph.</p>

    </body>

    </html>

    `;

    const { fileURL } = await Processor.generatePDFFromHtmlString(

    configuration,

    htmlString,

    );

    Generating a PDF from an image

    You can create a PDF from a single image or a series of images. Use the ImagePDFConfiguration object to set up your configuration:

    import RNFS from "react-native-fs";

    import { ImagePDFConfiguration } from "@nutrient-sdk/react-native";

    const Processor = NativeModules.RNProcessor;

    const configuration: ImagePDFConfiguration = {

    filePath: `file:///${RNFS.TemporaryDirectoryPath}/newImage.png`,

    images: [

    {

    imageUri: "path/to/image1.png",

    position: "center",

    pageSize: { width: 540, height: 846 },

    },

    {

    imageUri: "path/to/image2.png",

    position: "center",

    pageSize: { width: 540, height: 846 },

    },

    ],

    override: true,

    };

    const { fileURL } = await Processor.generatePDFFromImages(configuration);

    Generating a PDF from a template

    Nutrient allows you to generate PDF documents based on templates. Use the TemplatePDFConfiguration object to set up your configuration:

    import RNFS from "react-native-fs";

    import { TemplatePDFConfiguration } from "@nutrient-sdk/react-native";

    const Processor = NativeModules.RNProcessor;

    const configuration: TemplatePDFConfiguration = {

    filePath: `file:///${RNFS.TemporaryDirectoryPath}/newDocument.pdf`,

    override: true,

    templates: [

    {

    pageSize: { width: 540, height: 846 },

    backgroundColor: "rgba(0.871, 0.188, 0.643, 0.5)",

    template: "lines7mm",

    rotation: 90,

    pageMargins: { top: 10, left: 10, right: 10, bottom: 10 },

    },

    {

    pageSize: { width: 540, height: 846 },

    backgroundColor: "yellow",

    template: "dot5mm",

    },

    ],

    };

    const { fileURL } = await Processor.generatePDFFromTemplate(configuration);

    Opening the PDF documents

    Now that you’ve created your new document, you can display it using the PSPDFKitView component and add it to your application’s view stack.

    Because the Processor operations mentioned before are all asynchronous, the new PDF documents won’t be immediately available once the component mounts. One way to address this is to first show a loading spinner and use a state property to determine when the new document is available to show.

    In your constructor, declare a new state property called documentPath, and call the code to generate your PDF document:

    constructor(props: any) {

    super(props);

    this.pdfRef = React.createRef();

    this.state = {

    documentPath: null,

    };

    this.generatePDF();

    }

    After calling the relevant generate method to create your new document, update the state property with the new document path:

    this.setState({ documentPath: fileURL });

    Then, update your render function to the following:

    render() {

    if (this.state.documentPath === null) {

    return (

    <View style={[styles.container, styles.horizontal]} ref={React.createRef()}>

    <ActivityIndicator size="large" />

    </View>

    );

    } else {

    return (

    <NutrientView

    document={this.state.documentPath}

    configuration={{

    showThumbnailBar: 'scrollable',

    pageTransition: 'scrollContinuous',

    scrollDirection: 'vertical',

    }}

    ref={this.pdfRef}

    fragmentTag="PDF1"

    style={{flex: 1}}

    />

    );

    }

    }

    Include the following styles referenced by the example code at the end of your file:

    const styles = StyleSheet.create({

    container: {

    flex: 1,

    justifyContent: "center",

    },

    horizontal: {

    flexDirection: "row",

    justifyContent: "space-around",

    padding: 10,

    },

    });

    Conclusion

    In this post, you learned how to generate custom PDF documents in React Native using Nutrient React Native SDK. If you hit any snags, don’t hesitate to reach out to us for assistance. Visit our React Native guides for more information, and try our SDK for free.

    Explore related topics

    Try for free Ready to get started?

    Related SDK articles

    Explore more