open_pdf_annotation_engine 0.4.0
open_pdf_annotation_engine: ^0.4.0 copied to clipboard
Android-first Flutter plugin for editable PDF annotations, sidecar persistence, notes export, flattened export, and open PDF write-back without a commercial SDK.
import 'package:flutter/material.dart';
import 'package:open_pdf_annotation_engine/open_pdf_annotation_engine.dart';
void main() {
runApp(const DemoApp());
}
class DemoApp extends StatelessWidget {
const DemoApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Open PDF Annotation Engine v4')),
body: const Padding(
padding: EdgeInsets.all(16),
child: DemoBody(),
),
),
);
}
}
class DemoBody extends StatelessWidget {
const DemoBody({super.key});
@override
Widget build(BuildContext context) {
return FutureBuilder<String>(
future: _demo(),
builder: (context, snapshot) {
return SelectableText(snapshot.data ?? 'Running example...');
},
);
}
Future<String> _demo() async {
final engine = OpenPdfAnnotationEngine();
final annotation = PdfAnnotation(
type: AnnotationType.freeText,
pageNumber: 1,
color: const AnnotationColor(r: 220, g: 0, b: 0, opacity: 1),
createdAtIso: DateTime.now().toUtc().toIso8601String(),
rect: const PdfRect(left: 40, top: 80, right: 250, bottom: 120),
text: 'Hello from v4',
fontSize: 16,
tool: DrawTool.text,
);
try {
final result = await engine.saveAnnotations(
pdfPath: '/path/to/input.pdf',
documentId: 'sample',
annotations: [annotation],
mode: SaveMode.saveAsCopy,
outputPdfPath: '/path/to/input_annotated.pdf',
notesPdfPath: '/path/to/input+notes.pdf',
flatten: false,
);
return [
'success=${result.success}',
'output=${result.outputPdfPath}',
'notes=${result.notesPdfPath}',
'message=${result.message}',
].join('\n');
} catch (e) {
return 'Replace the placeholder file paths in the example before running.\n$e';
}
}
}