A comprehensive Flutter package for PDF annotation and editing with support for drawing, text annotations, shapes, and comments.
- ✅ PDF Viewing: Load and display PDF documents with zoom and pan support
- ✅ Drawing Tools: Free-hand drawing with customizable pen colors and stroke width
- ✅ Text Annotations: Add text overlays with customizable positioning and font size
- ✅ Shape Tools: Insert circles, rectangles, lines, arrows, and triangles
- ✅ Comment System: Add comment annotations with tap-to-place functionality
- ✅ Undo/Redo: Full undo/redo support for all annotation types
- ✅ Page Navigation: Navigate between PDF pages with intuitive controls
- ✅ Export: Save annotated PDFs to device storage
- ✅ Interactive Viewer: Zoom, pan, and scale support with transformation controls
Add this to your package's pubspec.yaml
file:
dependencies:
file_editor: ^0.0.1
Then run:
flutter pub get
This package relies on the following dependencies:
pdfx: ^2.9.1
- PDF rendering and document handlingpdf: ^3.11.3
- PDF generation and manipulationflutter_riverpod: ^2.6.1
- State managementpermission_handler: ^12.0.0+1
- Storage permissionspath_provider: ^2.1.5
- File path management
import 'package:file_editor/pdf_editor_lib.dart';
import 'package:flutter/material.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: PdfAnnotator('/path/to/your/pdf/file.pdf'),
);
}
}
import 'package:flutter_riverpod/flutter_riverpod.dart';
void main() {
runApp(
ProviderScope(
child: MyApp(),
),
);
}
The main widget for PDF annotation functionality.
PdfAnnotator(
String? filePath, {
Key? key,
})
filePath
: Path to the PDF file to be loaded and annotated
- Drawing Mode: Enable/disable free-hand drawing
- Pen Color Selection: Choose from red, blue, green, black, or yellow
- Text Annotations: Add positioned text with customizable size
- Shape Tools: Insert various geometric shapes
- Comment System: Add comment annotations at specific positions
- Page Navigation: Move between PDF pages
- Undo/Redo: Revert or restore annotation changes
- Save Functionality: Export annotated PDF
Free-hand drawing with customizable pen properties:
- Colors: Red, Blue, Green, Black, Yellow
- Stroke Width: Adjustable stroke width (default: 3.0)
- Stroke Cap: Rounded line endings
Positioned text overlays with:
- Editable Text: Multi-line text input
- Repositioning: Drag to move text annotations
- Font Size: Adjustable text size
- Color Support: Customizable text colors
Geometric shapes including:
- Circle: Perfect circles with drag-resize capability
- Rectangle: Rectangles with corner handles
- Line: Straight lines with endpoint controls
- Arrow: Directional arrows
- Triangle: Triangular shapes
Positioned comment bubbles:
- Tap-to-Place: Click anywhere to add comments
- Comment Dialog: Rich text input for comments
- Visual Indicators: Orange comment icons
- Delete Functionality: Remove comments with delete button
The top app bar includes:
- Pen Color Dropdown: Select drawing color
- Comment Toggle: Enable/disable comment placement mode
- Draw/Shapes Menu: Access drawing and shape tools
- Save Button: Export annotated PDF
Floating page controls provide:
- Previous/Next Page: Navigate between pages
- Page Counter: Current page / total pages display
- Undo/Redo: Quick access to undo/redo functions
The library uses Riverpod for state management with the following providers:
pdfEditorProvider
: Main state provider for PDF editor functionality- Manages document state, annotations, current page, and user interactions
The library handles the following permissions automatically:
- Storage Access: For reading PDF files and saving annotated versions
- File System: Access to device storage directories
lib/
├── pdf_editor_lib.dart # Main library export
└── src/
├── pdf/
│ ├── pdf_annotator.dart # Main PDF annotator widget
│ ├── pdf_annotator_riverpods.dart # State management
│ ├── pdf_annotator_state.dart # State model
│ ├── comment_annotation.dart # Comment annotation model
│ └── PdfEditorWidgetWrapper.dart # Widget wrapper
├── shape/
│ ├── shape.dart # Shape model
│ └── draggable_resizable_shape.dart # Interactive shape widget
├── text_annotation/
│ ├── text_annotation.dart # Text annotation model
│ ├── text_sticker.dart # Text overlay widget
│ └── stroke_segment.dart # Drawing stroke model
└── utils/
├── shape_type.dart # Shape type enumeration
├── string_extension.dart # String utilities
├── permission_request_handler.dart # Permission handling
└── storage_directory_path.dart # File path utilities
import 'package:file_editor/pdf_editor_lib.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
class BasicPdfViewer extends ConsumerWidget {
final String pdfPath;
const BasicPdfViewer({required this.pdfPath, Key? key}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
return Scaffold(
body: PdfAnnotator(pdfPath),
);
}
}
class CustomPdfEditor extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'PDF Editor',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: ProviderScope(
child: PdfAnnotator('/storage/emulated/0/Documents/sample.pdf'),
),
);
}
}
-
PDF Not Loading
- Ensure the file path is correct and accessible
- Check file permissions
- Verify the file is a valid PDF format
-
Annotations Not Saving
- Confirm storage permissions are granted
- Check available storage space
- Ensure write permissions to the target directory
-
Performance Issues
- Large PDF files may require more memory
- Consider implementing pagination for very large documents
- Monitor device memory usage
The library includes built-in error handling for:
- Invalid file paths
- Unsupported file formats
- Permission denied scenarios
- Storage access failures
This library is actively being developed. Key areas for contribution:
- Additional Shape Types: Extend the shape toolkit
- Advanced Text Formatting: Rich text support
- Annotation Export: Export annotations to various formats
- Performance Optimization: Improve rendering for large documents
- Accessibility: Add screen reader and keyboard navigation support
This project is licensed under the terms specified in the LICENSE file.
See CHANGELOG.md for a detailed history of changes and updates.
Note: This library is currently in version 0.0.1 and under active development. Some features may be experimental or subject to change in future releases.