pdfrx 2.6.5 copy "pdfrx: ^2.6.5" to clipboard
pdfrx: ^2.6.5 copied to clipboard

pdfrx is a rich and fast PDF viewer and manipulation plugin built on the top of PDFium. Supports viewing, editing, combining PDFs on Android, iOS, Windows, macOS, Linux, and Web.

pdfrx #

Build Test

pdfrx is a rich and fast PDF viewer and manipulation plugin for Flutter. It provides ready-to-use widgets for displaying and editing PDF documents, including page manipulation, document combining, and image import in your Flutter applications.

This plugin is built on top of pdfrx_engine, which handles the low-level PDF rendering and manipulation using PDFium. The separation allows for a clean architecture where:

  • pdfrx (this package) - Provides Flutter widgets, UI components, platform integration, and PDF editing features (page manipulation, combining, image import)
  • pdfrx_engine - Handles PDF parsing, rendering, and manipulation without Flutter dependencies

The plugin supports Android, iOS, Windows, macOS, Linux, and Web.

Interactive Demo #

A demo site using Flutter Web

pdfrx

Multi-platform support #

  • Android
  • iOS
  • Windows
  • macOS
  • Linux (even on Raspberry Pi)
  • Web (WASM)

Example Code #

The following fragment illustrates the easiest way to show a PDF file in assets:

import 'package:material_ui/material_ui.dart';
import 'package:pdfrx/pdfrx.dart';

...

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Pdfrx example'),
        ),
        body: PdfViewer.asset('assets/hello.pdf'),
      ),
    );
  }
}

Anyway, please follow the instructions below to install on your environment.

Getting Started #

Installation #

Add this to your package's pubspec.yaml file and execute flutter pub get:

dependencies:
  pdfrx: ^2.6.5

Note: You only need to add pdfrx to your dependencies. The pdfrx_engine package is automatically included as a dependency of pdfrx.

Initialization #

If you access the document API directly (for example, opening a PdfDocument before any pdfrx widget is built), call pdfrxFlutterInitialize once during app startup:

import 'package:flutter/widgets.dart';
import 'package:pdfrx/pdfrx.dart';

Future<void> main() {
  WidgetsFlutterBinding.ensureInitialized();
  pdfrxFlutterInitialize(); // Required when using engine APIs before widgets
  runApp(const MyApp());
}

For more information, see pdfrx Initialization

Native PDFium Packaging #

Native Flutter builds use pdfium_flutter and pdfium_dart to provide PDFium:

  • Android, Linux, and Windows bundle PDFium through Dart native assets.
  • iOS and macOS link the PDFium XCFramework through CocoaPods or Swift Package Manager.
  • The native-assets link hooks avoid bundling an extra libpdfium.dylib from pdfium_dart on iOS/macOS Flutter apps.

Note for Windows #

REQUIRED: You must enable Developer Mode to build pdfrx on Windows.

The build process uses symbolic links which requires Developer Mode to be enabled. If Developer Mode is not enabled:

  • The build will fail with an error message
  • You will see a link to Microsoft's official instructions
  • You must enable Developer Mode and restart your computer before building

Please follow Microsoft's official guide to enable Developer Mode as the exact steps may vary depending on your Windows version.

Breaking change: Material UI migration #

Since pdfrx 2.5.0, its Material widgets use material_ui package. To preserve localized PDF menu labels and theming, provide material_ui localizations and a material_ui.Theme; Flutter Material's equivalents are separate types. Without material_ui localizations, the default PDF menu labels fall back to English.

For setup and coexistence with existing Flutter Material apps, see the official Material UI migration instructions and Flutter's migration guide.

Note for iOS/macOS: Using CoreGraphics Instead of PDFium #

For iOS and macOS apps, you can optionally use pdfrx_coregraphics to render PDFs with Apple's native CoreGraphics/PDFKit instead of the PDFium XCFramework. This can significantly reduce your app size by removing PDFium dependencies on Darwin platforms.

⚠️ Note: pdfrx_coregraphics is experimental and has some limitations. See the package documentation for details.

To use CoreGraphics rendering:

  1. Add pdfrx_coregraphics to your dependencies
  2. Set the CoreGraphics entry functions before initializing pdfrx
  3. Optionally remove PDFium dependencies to reduce app size

For complete installation instructions and app size reduction steps, see the pdfrx_coregraphics README.

PdfViewer constructors #

For opening PDF files from various sources, there are several constructors available in PdfViewer:

Customizations/Features #

See pdfrx Documentation for customizations/features.

Additional Widgets #

PdfDocumentViewBuilder/PdfPageView #

PdfPageView is just another PDF widget that shows only one page. It accepts PdfDocument and page number to show a page within the document.

PdfDocumentViewBuilder is used to safely manage PdfDocument inside widget tree and it accepts builder parameter that creates child widgets.

The following fragment is a typical use of these widgets:

PdfDocumentViewBuilder.asset(
  'asset/test.pdf',
  builder: (context, document) => ListView.builder(
    itemCount: document?.pages.length ?? 0,
    itemBuilder: (context, index) {
      return Container(
        margin: const EdgeInsets.all(8),
        height: 240,
        child: Column(
          children: [
            SizedBox(
              height: 220,
              child: PdfPageView(
                document: document,
                pageNumber: index + 1,
                alignment: Alignment.center,
              ),
            ),
            Text(
              '${index + 1}',
            ),
          ],
        ),
      );
    },
  ),
),

PdfDocument Management #

PdfDocumentViewBuilder can accept PdfDocumentRef from PdfViewer to safely share the same PdfDocument instance. For more information, see example/viewer/lib/thumbnails_view.dart.

API Documentation #

Flutter Widgets (pdfrx) #

Low-Level PDF API (pdfrx_engine) #

For advanced use cases requiring direct PDF manipulation without Flutter widgets, see the pdfrx_engine API reference. This includes:

345
likes
160
points
461k
downloads
screenshot

Documentation

API reference

Publisher

verified publisherespresso3389.jp

Weekly Downloads

pdfrx is a rich and fast PDF viewer and manipulation plugin built on the top of PDFium. Supports viewing, editing, combining PDFs on Android, iOS, Windows, macOS, Linux, and Web.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

collection, crypto, flutter, material_ui, path, path_provider, pdfium_flutter, pdfrx_engine, rxdart, synchronized, url_launcher, vector_math, web, yaml

More

Packages that depend on pdfrx