Skip to content
ComPDF

Integrate the PDF Viewer Package

compdf_viewer is a ready-to-use Flutter PDF viewer package built on top of ComPDF Flutter SDK. Rather than building PDF viewing UI from scratch, you can drop this package into your project and get a fully interactive PDF reading experience — including annotations, bookmarks, text search, thumbnails, and more — out of the box.

The package uses GetX for routing, state management, and dependency injection, and ships with English and Chinese localizations.

AndroidiOS
Android screenshotAndroid screenshot

What's Included

CategoryDetails
PDF ViewingSingle page, double page, and continuous scroll modes
AnnotationsNote, highlight, underline, strikeout, ink drawing, shapes (rectangle, circle, line, arrow), stamps, signatures
NavigationBOTA panel — Bookmarks, Outlines, Thumbnails, Annotations list
Text SearchFull-text search with context snippets and result highlighting
Document SecurityPassword protection, encryption, permission settings
Content EditingEdit PDF text and images directly; undo/redo support
ExportConvert PDF pages to images, flatten annotations
UIDark mode support, built-in English and Chinese translations

Package Structure

The package follows a feature-based architecture with GetX. Each feature is a self-contained module with its own controller, model, and widgets.

dart
lib/
├── compdf_viewer.dart   # Public API & exports
├── core/                # Global settings, SDK initialization, bindings, constants
├── features/
│   ├── viewer/          # Main PDF rendering page + controller
│   ├── annotation/      # Annotation toolbar & property editors
│   ├── bota/            # Bookmarks, Outlines, Thumbnails, Annotations list
│   ├── search/          # Full-text search
│   ├── navigation/      # Side drawer
│   ├── security/        # Password/encryption dialogs
│   ├── convert/         # PDF-to-image export
│   └── info/            # Document metadata display
├── l10n/                # English and Chinese translations
├── router/              # GetX route definitions
├── shared/              # Reusable widgets, controllers, dialogs
└── utils/               # File, page, screen utilities

Key classes:

ClassRole
PdfViewerGlobalSDK initialization and logger
PdfViewerControllerMain PDF viewer state and controls
PdfAnnotationToolBarControllerAnnotation tool selection and property management
PdfSearchControllerText search state and result navigation
PdfViewerRoutesRoute path constants
PdfViewerPagesGetX page configuration list

Prerequisites

RequirementMinimum Version
Flutter3.3.0
Dart SDK3.0.5
Android minSdkVersion21
iOS deployment target12.0
ComPDF licenseRequired — get a free trial

Getting Started

Add the dependency

compdf_viewer is located in the ComPDF Flutter SDK repository under example/packages/compdf_viewer. Copy it into your project, then reference it in pubspec.yaml:

yaml
dependencies:
  flutter:
    sdk: flutter
  compdf_viewer:
    path: packages/compdf_viewer
  get: ^4.7.2

Fetch packages

bash
flutter pub get

Add your license file

Copy your ComPDF license file to your app's assets folder (e.g. assets/license_key_flutter.xml) and declare it in pubspec.yaml:

yaml
flutter:
  assets:
    - assets/license_key_flutter.xml

Initialize the SDK

Call PdfViewerGlobal.init() before runApp():

dart
import 'package:compdf_viewer/compdf_viewer.dart';
import 'package:flutter/material.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize ComPDF with your license file path
  await PdfViewerGlobal.init('assets/license_key_flutter.xml');

  runApp(const MyApp());
}

Register routes and translations

compdf_viewer ships with GetX routing and i18n. Register them in your GetMaterialApp:

dart
import 'package:get/get.dart';
import 'package:compdf_viewer/compdf_viewer.dart';

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      // Register translations (English + Chinese)
      translations: PdfViewerTranslations(),
      locale: Get.deviceLocale,
      fallbackLocale: const Locale('en', 'US'),

      // Register PDF viewer routes
      getPages: [
        ...PdfViewerPages.routes,
        // ...your other routes
      ],

      home: const HomePage(),
    );
  }
}

Open a PDF

Navigate to the PDF viewer page by passing the absolute file path:

dart
Get.toNamed(
  PdfViewerRoutes.pdfPage,
  arguments: {'document': '/absolute/path/to/document.pdf'},
);

That's it. The viewer opens with a full annotation toolbar, search, bookmarks, and all built-in features enabled.

Dependencies

PackagePurpose
compdfkit_flutterPDF rendering and SDK core
getState management, DI, and routing
shared_preferencesPersistent viewer settings
flutter_colorpickerAnnotation color picker UI
share_plusShare PDF files
file_pickerOpen files from device storage
path_providerAccess device directories
flutter_svgRender toolbar SVG icons
loggerDebug and error logging

Further Reading