pdf_viewer_pro

pub.flutter-io.cn License: MIT Platform Publisher

A full-featured PDF viewer for Flutter (Android & iOS) with annotations, bookmarks, DRM protection, search, thumbnails, auto-scroll, and dark/light theme support. Built on PDFium via pdfrx.

Platform Support

Android iOS
βœ… βœ…

Features

  • πŸ“„ High-performance PDF rendering using PDFium FFI (pdfrx)
  • πŸ”– Bookmarks β€” add, remove, navigate, sync with server
  • ✏️ Annotations β€” pen drawing, highlighter, notes, eraser with undo/redo
  • πŸ”€ Text Selection β€” select and copy PDF text
  • πŸ” Search β€” full-text search with match highlighting
  • πŸ–ΌοΈ Thumbnails β€” page thumbnail grid drawer
  • πŸ“’ Table of Contents β€” hierarchical PDF outline navigation
  • πŸŒ™ Dark/Light theme support
  • ↔️ Scroll direction β€” toggle vertical/horizontal scroll
  • ⏩ Auto-scroll with configurable interval
  • πŸ“Š Page slider β€” bottom navigation bar with page preview
  • πŸ”’ DRM protection β€” screenshot/screen-recording prevention
  • β˜€οΈ Keep screen on while reading
  • πŸ“Š Session tracking β€” reading duration and page progress
  • πŸ”— Authenticated downloads via custom HTTP headers
  • ☁️ Server sync via callbacks (bookmarks, annotations, sessions)
  • πŸ’Ύ Custom storage β€” pluggable storage backend
  • πŸ“€ Share β€” share PDF or content
  • πŸͺΆ SimplePdfViewer β€” lightweight view-only widget for invoices/docs

Getting Started

dependencies:
  pdf_viewer_pro: ^0.0.2

Basic Usage

import 'package:pdf_viewer_pro/pdf_viewer_pro.dart';

// Open from file path
Navigator.push(context, MaterialPageRoute(
  builder: (_) => PdfViewerScreen(
    filePath: '/path/to/document.pdf',
    title: 'My Document',
  ),
));

// Open from URL
Navigator.push(context, MaterialPageRoute(
  builder: (_) => PdfViewerScreen(
    fileUrl: 'https://example.com/document.pdf',
    title: 'My Document',
  ),
));

Feature Configuration

PdfViewerScreen(
  filePath: '/path/to/document.pdf',
  title: 'My Document',
  bookId: 42,                       // For bookmarks/annotations persistence
  featureConfig: PdfViewerFeatureConfig(
    enableBookmarks: true,
    enableAnnotations: true,
    enableSearch: true,
    enableTextSelection: true,
    enableThumbnails: true,
    enableTableOfContents: true,
    enableAutoScroll: true,
    enableDarkModeToggle: true,
    enableFullscreen: true,
    enablePageSlider: true,
    enableScreenProtection: false,
    enableKeepScreenOn: true,
    enableSessionTracking: true,
    enableScrollDirectionToggle: true,
    enableSettings: true,
    enableShare: true,
  ),
);

Built-in Presets

// All features enabled
featureConfig: PdfViewerFeatureConfig.fullFeatures

// View-only (no annotations/bookmarks)
featureConfig: PdfViewerFeatureConfig.readOnly

// Bare minimum (page slider only)
featureConfig: PdfViewerFeatureConfig.minimal

Simple View-Only Widget

For invoices, receipts, and documents that only need viewing:

// From file path
SimplePdfViewer.file('/path/to/invoice.pdf')

// From bytes
SimplePdfViewer.data(pdfBytes, sourceName: 'invoice.pdf')

// From URL
SimplePdfViewer.uri(Uri.parse('https://example.com/doc.pdf'))

Theme Customization

themeConfig: PdfViewerThemeConfig(
  primaryColor: Colors.blue,
  lightBackgroundColor: Colors.white,
  darkBackgroundColor: Color(0xFF121212),
  cardBorderRadius: 12.0,
),

Server Sync

serviceConfig: PdfViewerServiceConfig(
  // Sync bookmarks with your server
  onBookmarksSync: (bookId, bookmarks) async {
    await myApi.saveBookmarks(bookId, bookmarks);
  },
  onBookmarksLoad: (bookId) async {
    return await myApi.loadBookmarks(bookId);
  },
  // Track reading sessions
  onSessionStart: (bookId) async {
    await myApi.startSession(bookId);
  },
  onSessionEnd: (bookId, durationSeconds, currentPage, totalPages) async {
    await myApi.endSession(bookId, durationSeconds);
  },
  // Authenticated file access
  httpHeaders: {'Authorization': 'Bearer $token'},
),

Libraries

pdf_viewer_pro
PDF Viewer Pro - A full-featured PDF viewer for Flutter