New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-native-pdf-painter

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-pdf-painter

Display PDFs with handdrawn annotation support

latest
Source
npmnpm
Version
0.10.1
Version published
Maintainers
1
Created
Source

Welcome to react-native-pdf-painter👋

Your React Native PDF Viewer with native annotation support

License: MIT Build Status npm version

Easy-to-use react native component for efficient displaying of PDFs, with finger and pen support for hand drawing. Supports PencilKits ToolPicker out-of-the-box on iOS.

Demo Android Demo iOS

📥 Installation

npm install react-native-pdf-painter

or

yarn add react-native-pdf-painter

Starting from version 0.8.0 of this library, it's only compatible with React Native >= 0.77! If you are using an older version of React Native, please use the version 0.7.2 of this library.

iOS

cd ios && pod install

WARNING

This library is completely written as Fabric components and is therefore only compatible with the new architecture!

For Android users: This library uses androidx.ink in version 1.0.0alpha3, which means that this library is not recommended for production use yet! Some issues have already been discovered (e.g. flickering when drawing)

For iOS users: Annotations only work for iOS versions >= 16, everything below can view PDFs but not draw.

The annotations created with this library are not embedded in the PDF file itself! Instead it creates a new file containing the annotations in a proprietary json-like (compressed) format which is not platform interoperable.

▶️ Usage

Import the PdfAnnotationView component and assign a path to a pdf file to it. If you want to display the drawn annotations, add the annotationFile property.

import { PdfAnnotationView } from "react-native-pdf-painter";

<PdfAnnotationView
    pdfUrl={pathToPdfFile}
    annotationFile={pathToAnnotationFile}
    autoSave={true} // automatically save annotations on unmount to the annotationFile
/>

You can handle saving and loading of the annotations manually by using the saveAnnotations and loadAnnotations methods:

import { PdfAnnotationView, type Handle } from "react-native-pdf-painter";

const Component = () => {
    const ref = useRef<Handle>(null);

    const saveAnnotations = () => ref.current?.saveAnnotations(FILE_PATH);
    const loadAnnotations = () => ref.current?.loadAnnotations(FILE_PATH);

    return (
        <PdfAnnotationView
            ref={ref}
            pdfUrl={pathToPdfFile}
            annotationFile={pathToAnnotationFile}
            autoSave={true} // automatically save annotations on unmount to the annotationFile
        />
    );
}

Refer to example for detailed usage example.

Props, Methods & types

NamePlatformTypeDescription
pdfUrlios, androidString?Local URL of the PDF file
annotationsFileios, androidString?Local URL of the files used for annotations (file extension doesn't matter)
thumbnailModeios, androidBoolean?Displays only the first page without interaction
autoSaveios, androidBoolean?Automatically save file after changing pdf url or unmounting the component
brushSettingsios, androidBrushSettingsPass undefined to disable drawing and pass an BrushSettings object to enable drawing with the provided configuration
hidePaginationios, androidBoolean?Disable the pagination buttons at the bottom
iosToolPickerVisibleiosBoolean?Show/Hide the PencilKit ToolPicker
currentPageios, androidnumber?(Optional) Controlled page selection
containerStylesios, androidStyleProp?Override container styles
pageIndicatorContainerStylesios, androidStyleProp?Override container styles of page indicator bar
androidBeyondViewportPageCountandroidNumber of pages which are rendered before/after the current page
onPageCountios, android((pageCount: number) => unknown)?Event fired when the number of pages changes
onPageChangeios, android((page: number) => unknown)?Event fired when the current page changes
onDocumentFinishedios, android((event: BubblingEventHandler) => unknown)?Event fired when the user wants to navigate to the next/previous page but is already at the end/beginning
onTapios, android((event: BubblingEventHandler) => unknown)?Event fired when the user taps on the PDF page
onLinkCompletedios, android((event: BubblingEventHandler) => unknown)?Event fired when the brush settings is link and the user has finished creating the link

Info: The ToolPicker is fixed and always at the bottom of the iPhone screen! Keep this in mind when designing your PDF Viewer screen!

saveAnnotations(filePath: string): void

Save the current drawings on all pages to the provided file path.

loadAnnotations(filePath: string): void

Load the drawings of all pages from the provided file path.

undo(): void

Undo the last change on the current page

redo(): void

Redo the last undone change on the current page

clear(): void

Delete all drawings on the current page

setPage(page: number): void

Manually change the page of the pdf viewer

BrushSettings

interface BrushSettings {
    type?: WithDefault<BrushType, 'marker'>;
    color: string;
    size: Float;
}

BrushType

type BrushType =
    | 'marker'
    | 'pressure-pen'
    | 'highlighter'
    | 'eraser'
    | 'link'
    | 'none';

How it works

Android

This library uses the PdfRenderer class to render the pages of the pdf as a bitmap, scaled to a higher resolution (to make zoomed pages look sharp enough). For drawing, the new androidx ink library is used.

iOS

Uses PdfKit in conjunction with PencilKit to support drawing on pages.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Keywords

react-native

FAQs

Package last updated on 25 Nov 2025

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