Skip to content

About

This demo app provides a complete reference implementation of all PDF viewing, bookmarking, export, and analytics features available in the `react-native-pdf-jsi` package. Use this as a starting point for your own PDF viewer applications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š React Native PDF JSI - Demo App

A comprehensive demonstration app showcasing all features of the react-native-pdf-jsi package

This demo app provides a complete reference implementation of all PDF viewing, bookmarking, export, and analytics features available in the react-native-pdf-jsi package. Use this as a starting point for your own PDF viewer applications.

npm version npm downloads GitHub stars license


🎯 Purpose

This demo app serves as:

  • Reference Implementation - See how to integrate all package features correctly
  • Testing Ground - Verify package functionality and features
  • Learning Resource - Understand best practices for PDF viewer apps
  • GitHub Showcase - Demonstrate the package's capabilities to developers

✨ Features Demonstrated

Core Features

  • βœ… PDF viewing with zoom, pan, and navigation
  • βœ… Page-by-page navigation
  • βœ… Real-time page tracking

Bookmarks

  • βœ… Create bookmarks with custom names and colors
  • βœ… View all bookmarks in a list
  • βœ… Navigate to bookmarked pages
  • βœ… Delete bookmarks
  • βœ… Visual bookmark indicator on PDF viewer

Export

  • βœ… Export single page to image (PNG/JPEG)
  • βœ… Export multiple pages to images
  • βœ… Export custom page ranges
  • βœ… Export PDF text content
  • βœ… All exports saved to Downloads/PDFDemoApp folder

PDF Operations

  • βœ… Split PDF into multiple files
  • βœ… Extract specific pages to new PDF
  • βœ… Rotate pages
  • βœ… Compress PDF files
  • βœ… All operations save results to Downloads folder

Analytics

  • βœ… Reading progress tracking
  • βœ… Time spent per session
  • βœ… Pages read statistics
  • βœ… Reading speed metrics
  • βœ… Session history

File Management (Android)

  • βœ… Download PDFs to public storage
  • βœ… Open Downloads folder
  • βœ… Files visible in system file manager

πŸš€ Quick Start

Prerequisites

  • Node.js >= 20
  • React Native 0.82+
  • Android Studio (for Android development)
  • Xcode (for iOS development, macOS only)

Installation

  1. Clone or download this repository
cd DemoApp
  1. Install dependencies
npm install

Note: This demo app uses react-native-pdf-jsi v3.4.0. To install the latest version in your own project:

npm install react-native-pdf-jsi@latest
  1. Install iOS dependencies (iOS only)
cd ios && bundle exec pod install && cd ..
  1. Run the app
# Android
npm run android

# iOS
npm run ios

πŸ“ Project Structure

DemoApp/
β”œβ”€β”€ App.tsx                 # Main application component
β”œβ”€β”€ components/
β”‚   └── BookmarkIndicator.jsx  # Floating bookmark button component
β”œβ”€β”€ node_modules/
β”‚   └── react-native-pdf-jsi/  # Package installed locally
β”œβ”€β”€ android/                # Android native code
β”œβ”€β”€ ios/                    # iOS native code
└── README.md              # This file

🎨 UI Components

The app uses components from react-native-pdf-jsi package:

  • Toolbar - Top navigation bar with feature buttons
  • BookmarkModal - Create/edit bookmarks
  • BookmarkListModal - View all bookmarks
  • BookmarkIndicator - Floating bookmark button
  • ExportMenu - Export options menu
  • OperationsMenu - PDF operations menu
  • AnalyticsPanel - Reading analytics display
  • Toast - Notification messages
  • LoadingOverlay - Loading indicator

πŸ“€ File Saving

All exported files and PDF operations save to:

Android: Downloads/PDFDemoApp/

Files are saved using Android's MediaStore API (Android 10+) for proper visibility in file managers.

Exported Files Location

  • Images: Downloads/PDFDemoApp/page_1_*.jpeg
  • Extracted PDFs: Downloads/PDFDemoApp/*_extracted_*.pdf
  • Split PDFs: Downloads/PDFDemoApp/*_part_*.pdf

All operations show success alerts with "Open Folder" option to view saved files.


πŸ”§ Key Implementation Patterns

1. PDF Path Management

The app uses multiple strategies to get the PDF file path:

const getPDFLocalPath = async (): Promise<string | null> => {
  // Method 1: From state (set by onLoadComplete)
  if (pdfFilePath && pdfFilePath.trim() !== '') {
    return pdfFilePath;
  }
  
  // Method 2: From PDF component ref
  if (pdfRef.current?.getPath) {
    return pdfRef.current.getPath();
  }
  
  // Method 3: From component state
  if (pdfRef.current?.state?.path) {
    return pdfRef.current.state.path;
  }
  
  return null;
};

2. File Download Pattern

All exports follow this pattern:

// 1. Export to cache first
const imagePath = await exportManager.exportPageToImage(...);

// 2. Download to public Downloads folder
const downloadedFiles = await downloadExportedPDFs(imagePath);

// 3. Show success alert with Open Folder option
Alert.alert('βœ… Export Successful', message, [
  { text: 'Done' },
  { 
    text: 'Open Folder',
    onPress: () => FileManager.openDownloadsFolder()
  }
]);

3. Page Number Handling

Important: ExportManager expects 1-indexed page numbers (Page 1, Page 2, etc.)

// βœ… Correct - Pass 1-indexed page number
await exportManager.exportPageToImage(pdfPath, pageNumber);

// ❌ Wrong - Don't convert to 0-indexed
await exportManager.exportPageToImage(pdfPath, pageNumber - 1);

The ExportManager handles conversion to 0-indexed internally for native modules.


πŸ“± Usage Examples

Export Current Page

await handleExport({
  type: 'single',
  page: currentPage,
  format: 'jpeg',
  quality: 0.9
});

Extract Pages

await handlePDFOperation('extract', {
  pages: [1, 5, 10] // 1-indexed page numbers
});

Split PDF

await handlePDFOperation('split', {
  ranges: [1, 5, 6, 10] // Flat array: [start1, end1, start2, end2]
});

πŸ› Troubleshooting

PDF Not Loading

  • Check internet connection if loading from URL
  • Verify PDF file exists if loading from local path
  • Check console logs for error messages

Exports Not Working

  • Ensure PDF has fully loaded (pdfFilePath is set)
  • Check that file path is valid (not empty or URI)
  • Verify native module is available

Files Not Visible in Downloads

  • Android 10+: Files use MediaStore API, should be visible automatically
  • Check Downloads/PDFDemoApp/ folder specifically
  • Use "Open Folder" button in success alert

Bookmark Issues

  • PDF must be loaded before creating bookmarks
  • Check that pdfIdentifier or pdfFilePath is set
  • BookmarkManager must be initialized

πŸ“ Code Highlights

State Management

// Core PDF State
const [pdfFilePath, setPdfFilePath] = useState<string>('');
const [currentPage, setCurrentPage] = useState<number>(1);
const [totalPages, setTotalPages] = useState<number>(0);

// Feature State
const [bookmarks, setBookmarks] = useState<any[]>([]);
const [currentBookmark, setCurrentBookmark] = useState<any>(null);
const [analytics, setAnalytics] = useState<any>(null);

Manager Initialization

useEffect(() => {
  const initializeManagers = async () => {
    // Import singleton instances
    exportManager = require('react-native-pdf-jsi/src/managers/ExportManager').default;
    bookmarkManager = require('react-native-pdf-jsi/src/managers/BookmarkManager').default;
    
    // Initialize if needed
    await bookmarkManager.initialize();
  };
  initializeManagers();
}, []);

πŸ”— Package Documentation

For detailed package documentation, visit:


πŸ“„ License

This demo app is provided as-is for reference purposes. The react-native-pdf-jsi package may have its own license terms.


🀝 Contributing

This is a demo/reference app. For issues or feature requests related to the package itself, please refer to the main package repository.


πŸ“ž Support

For questions about:


πŸ“¦ Package Information


Built with react-native-pdf-jsi v3.4.0

Last Updated: 2025-11-29


react-native-pdf-jsi-demo-app

About

This demo app provides a complete reference implementation of all PDF viewing, bookmarking, export, and analytics features available in the `react-native-pdf-jsi` package. Use this as a starting point for your own PDF viewer applications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages