pdfium_dart 0.1.3 copy "pdfium_dart: ^0.1.3" to clipboard
pdfium_dart: ^0.1.3 copied to clipboard

Dart FFI bindings for PDFium library. Provides low-level access to PDFium's C API from Dart.

pdfium_dart #

Dart FFI bindings for the PDFium library. This package provides low-level access to PDFium's C API from Dart.

This package is part of the pdfrx project.

Overview #

This package contains auto-generated FFI bindings for PDFium using ffigen. It is designed to be a minimal, pure Dart package that other packages can depend on to access PDFium functionality.

Key Features:

  • Pure Dart package with no Flutter dependencies
  • Auto-generated FFI bindings using ffigen
  • Provides direct access to PDFium's C API
  • Includes getPdfium() function for on-demand PDFium binary downloads
  • Supports Windows (x64), Linux (x64, ARM64), and macOS (x64, ARM64)

Usage #

Basic Usage #

This package is primarily intended to be used as a dependency by higher-level packages like pdfium_flutter and pdfrx_engine. Direct usage is possible but not recommended unless you need low-level PDFium access.

import 'package:pdfium_dart/pdfium_dart.dart';
import 'dart:ffi';

// If you already have PDFium loaded
final pdfium = PDFium(DynamicLibrary.open('/path/to/libpdfium.so'));

On-Demand PDFium Downloads #

The getPdfium function automatically downloads PDFium binaries on demand, making it easy to use PDFium in CLI applications or for testing without bundling binaries:

import 'package:pdfium_dart/pdfium_dart.dart';

void main() async {
  // Downloads PDFium binaries automatically if not cached
  final pdfium = await getPdfium();

  // Use PDFium API
  // ...
}

Note for macOS: The downloaded library is not codesigned. If you encounter issues loading the library, you may need to manually codesign it:

codesign --force --sign - <path_to_libpdfium.dylib>

The binaries are downloaded from bblanchon/pdfium-binaries and cached in the system temp directory.

Generating Bindings #

Prerequisites #

The ffigen process requires LLVM/Clang to be installed for parsing C headers:

  • macOS: Install via Homebrew

    brew install llvm
    
  • Linux: Install via package manager

    # Ubuntu/Debian
    sudo apt-get install libclang-dev
    
    # Fedora
    sudo dnf install clang-devel
    
  • Windows: Download and install LLVM from llvm.org

Regenerating Bindings #

To regenerate the FFI bindings:

  1. Run tests to download PDFium headers:

    dart test
    
  2. Generate bindings:

    dart run ffigen
    

The bindings are generated from PDFium headers using the configuration in ffigen.yaml.

Platform Support #

Platform Architecture Support
Windows x64
Linux x64, ARM64
macOS x64, ARM64

Note: For Flutter applications with bundled PDFium binaries, use the pdfium_flutter package instead.

0
likes
150
points
7.6k
downloads

Publisher

verified publisherespresso3389.jp

Weekly Downloads

Dart FFI bindings for PDFium library. Provides low-level access to PDFium's C API from Dart.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

archive, ffi, http, path

More

Packages that depend on pdfium_dart