How espresso3389/pdfrx works
Purpose and Entry Points
This pub-workspace monorepo delivers PDF rendering, viewing, and manipulation for Dart and Flutter. Its public package entry points are:
• Flutter UI API: packages/pdfrx/lib/pdfrx.dart
• Platform-agnostic document API: packages/pdfrx_engine/lib/pdfrx_engine.dart
• Direct PDFium FFI: packages/pdfium_dart/lib/pdfium_dart.dart
• Flutter PDFium packaging: packages/pdfium_flutter/lib/pdfium_flutter.dart
• Experimental Apple CoreGraphics backend: packages/pdfrx_coregraphics/lib/pdfrx_coregraphics.dart
PDFium Binding and Deployment Layer
PDFium is the primary rendering/manipulation engine. pdfium_dart exposes generated C FFI bindings and resolves a usable PDFium library; build/link hooks acquire and package native assets. pdfium_flutter supplies Flutter-specific loading and Darwin framework integration.
• packages/pdfium_dart/lib/src/pdfium_bindings.dart
• packages/pdfium_dart/lib/src/pdfium_loader.dart
• packages/pdfium_dart/hook/build.dart
• packages/pdfium_flutter/darwin/pdfium_flutter/Sources/main/pdfium_flutter.swift
Native targets include Android, iOS, macOS, Windows, and Linux. iOS/macOS use a PDFium XCFramework through CocoaPods or Swift Package Manager; other native environments use Dart native assets.
Engine: Document and Rendering Domain
pdfrx_engine is the non-Flutter boundary over PDFium. It defines document/page abstractions plus PDF-domain values for text, images, annotations, links, outlines, permissions, destinations, and editing operations. This layer can support CLI or server-side Dart consumers without widget dependencies.
• packages/pdfrx_engine/lib/src/pdf_document.dart
• packages/pdfrx_engine/lib/src/pdf_page.dart
• packages/pdfrx_engine/lib/src/pdfrx.dart
The control flow is initialization → document open/create → page/text/image/link operations → render or write/export. Native PDFium adaptation, file access/write callbacks, caching, and worker handling live behind the engine boundary:
• packages/pdfrx_engine/lib/src/native/pdfrx_pdfium.dart
• packages/pdfrx_engine/lib/src/native/pdfium_file_access.dart
• packages/pdfrx_engine/lib/src/native/worker.dart
Flutter Viewer Composition
pdfrx builds the interactive Flutter presentation layer on the engine. The viewer owns document presentation, viewport/layout state, page rendering, gestures, keyboard handling, overlays, search, selection, links, and scroll feedback.
• packages/pdfrx/lib/src/widgets/pdf_viewer.dart
• packages/pdfrx/lib/src/widgets/interactive_viewer.dart
• packages/pdfrx/lib/src/widgets/pdf_viewer_params.dart
Viewer behavior is delegated rather than hard-coded: sizing, zoom steps, and scroll interaction have interchangeable strategies.
• packages/pdfrx/lib/src/widgets/sizing/pdf_viewer_size_delegate.dart
• packages/pdfrx/lib/src/widgets/zoom_steps/pdf_viewer_zoom_steps_delegate.dart
• packages/pdfrx/lib/src/widgets/scroll_interaction/pdf_viewer_scroll_interaction_delegate.dart
Web and Apple Backend Boundaries
Web uses bundled WebAssembly plus JavaScript client/worker assets, separated from native loading code.
• packages/pdfrx/assets/pdfium.wasm
• packages/pdfrx/assets/pdfium_client.js
• packages/pdfrx/lib/src/wasm/pdfrx_wasm.dart
On Apple platforms, an experimental plugin can substitute system PDFKit/CoreGraphics while preserving the pdfrx widget-facing API.
• packages/pdfrx_coregraphics/darwin/pdfrx_coregraphics/Sources/PdfrxCoregraphicsPlugin.swift
• packages/pdfrx_coregraphics/lib/pdfrx_coregraphics.dart
Consumer Applications and Delivery
The primary executable examples are Flutter applications: a full viewer and a PDF-combine/page-rearrangement tool.
• packages/pdfrx/example/viewer/lib/main.dart
• packages/pdfrx/example/pdf_combine/lib/main.dart
CI is GitHub Actions-based, including build/test, static analysis, Pages documentation, and Apple PDFium release automation.
• .github/workflows/build-test.yml
• .github/workflows/pdfium-apple-release.yml
Main entry points: pdf_viewer.dart PDF viewer · pdfium_dart.dart pdfium_dart API · pdfrx_engine.dart pdfrx_engine API · pdfrx.dart pdfrx Flutter API
Components 19
PDFium Runtime
Native binding, loading, and platform packaging.
- pdfium_dart API · Direct PDFium FFI entry point.
packages/pdfium_dart/lib/pdfium_dart.dart - Generated FFI bindings
packages/pdfium_dart/lib/src/pdfium_bindings.dart - PDFium loader · Resolves a usable native PDFium library.
packages/pdfium_dart/lib/src/pdfium_loader.dart - Native asset build hook · Acquires and packages PDFium native assets.
packages/pdfium_dart/hook/build.dart - pdfium_flutter · Flutter-specific PDFium loading and Darwin integration.
packages/pdfium_flutter/lib/pdfium_flutter.dart - Darwin PDFium bridge · Integrates the PDFium XCFramework for Apple platforms.
packages/pdfium_flutter/darwin/pdfium_flutter/Sources/main/pdfium_flutter.swift
Document Engine
Platform-agnostic PDF domain and native adaptation.
- pdfrx_engine API · Platform-agnostic document API.
packages/pdfrx_engine/lib/pdfrx_engine.dart - Document and page domain · Documents, pages, text, images, links, annotations, and editing values.
packages/pdfrx_engine/lib/src/pdf_document.dart - Native PDFium adapter · Handles PDFium access, callbacks, caching, and workers.
packages/pdfrx_engine/lib/src/native/pdfrx_pdfium.dart
Flutter Viewer
Interactive widget composition and web runtime.
- pdfrx Flutter API · Public widget-facing PDF API.
packages/pdfrx/lib/pdfrx.dart - PDF viewer · Owns presentation, page rendering, overlays, search, selection, and links.
packages/pdfrx/lib/src/widgets/pdf_viewer.dart - Interactive viewport · Manages layout state, gestures, keyboard input, and scroll feedback.
packages/pdfrx/lib/src/widgets/interactive_viewer.dart - Viewer strategies · Interchangeable sizing, zoom-step, and scroll-interaction behavior.
packages/pdfrx/lib/src/widgets/sizing/pdf_viewer_size_delegate.dart - WebAssembly PDFium · Bundled WASM with JavaScript client and worker assets.
packages/pdfrx/assets/pdfium.wasm - WASM adapter · Separates web PDFium access from native loading.
packages/pdfrx/lib/src/wasm/pdfrx_wasm.dart
Apple Alternative
Experimental system-framework backend.
- CoreGraphics backend · Preserves the widget-facing API using PDFKit/CoreGraphics.
packages/pdfrx_coregraphics/lib/pdfrx_coregraphics.dart
Consumers & Delivery
- Viewer example
packages/pdfrx/example/viewer/lib/main.dart - PDF combine example · Page rearrangement and PDF-combine tool.
packages/pdfrx/example/pdf_combine/lib/main.dart - Build and release CI · Builds, tests, analyzes, publishes docs, and releases Apple PDFium.
.github/workflows/build-test.yml
Connections 19
- pdfium_dart API → Generated FFI bindings: exposes
- pdfium_dart API → PDFium loader: loads through
- Native asset build hook → PDFium loader: packages assets for
- pdfium_flutter → pdfium_dart API: uses
- pdfium_flutter → Darwin PDFium bridge: integrates
- pdfrx_engine API → Document and page domain: exports
- pdfrx_engine API → Native PDFium adapter: delegates native work to
- Native PDFium adapter → pdfium_dart API: adapts
- pdfrx Flutter API → PDF viewer: exports
- PDF viewer → Interactive viewport: composes
- PDF viewer → Viewer strategies: delegates behavior to
- PDF viewer → pdfrx_engine API: opens, renders, and edits through
- WASM adapter → WebAssembly PDFium: loads
- pdfrx Flutter API → WASM adapter: uses on web
- CoreGraphics backend → pdfrx Flutter API: substitutes backend for
- Viewer example → pdfrx Flutter API: consumes
- PDF combine example → pdfrx_engine API: consumes
- Build and release CI → Native asset build hook: builds and tests
- Build and release CI → Darwin PDFium bridge: releases Apple PDFium