pdf_toolkit is a Flutter plugin that provides low-level PDF document manipulation capabilities using Foreign Function Interface (FFI) and third-party C libraries. This plugin allows developers to perform various operations on PDF documents, such as merging, splitting, and extracting pages.
- PDF Merging: Combine multiple PDF documents into a single file.
- PDF Splitting: Extract specific pages or ranges from a PDF document.
- PDF Page Extraction: Extract individual pages from a PDF file.
- Low-Level Manipulation: Direct access to PDF internals for advanced customization.
To use pdf_toolkit in your Flutter project, add it to your pubspec.yaml
file:
dependencies:
pdf_toolkit: ^1.0.0
Then, run:
flutter pub get
No additional setup is required for Android.
For iOS, you may need to add the following entry to your Info.plist file to enable the use of FFI:
<key>io.flutter.embedded_views_preview</key>
<true/>
import 'package:pdf_toolkit/pdf_toolkit.dart';
// Specify input PDF files
List<String> inputPaths = ['path/to/file1.pdf', 'path/to/file2.pdf'];
// Specify the output path for the merged PDF
String outputPath = 'path/to/merged.pdf';
// Merge PDFs
try {
await PdfTool.mergePdfs(inputPaths, outputPath);
print('PDFs merged successfully!');
} catch (e) {
print('Error merging PDFs: $e');
}
// Specify the input PDF file
String inputPath = 'path/to/source.pdf';
// Specify the output path for the split PDFs
String outputDir = 'path/to/split/';
// Specify the page range to extract (e.g., '1-3' for pages 1 to 3)
String pageRange = '1-3';
// Split PDF
try {
await PdfTool.splitPdf(inputPath, outputDir, pageRange);
print('PDF split successfully!');
} catch (e) {
print('Error splitting PDF: $e');
}
Merges multiple PDF files into a single PDF.
inputPaths
: List of paths to the input PDF files.outputPath
: Path to the output merged PDF file.
Splits a PDF into multiple files based on the specified page range.
inputPath
: Path to the input PDF file.outputDir
: Directory path where the split PDFs will be saved.pageRange
: Page range to extract (e.g., '1-3' for pages 1 to 3).
Contributions and bug reports are welcome! Please create issues for any bugs or feature requests. Pull requests are encouraged.
This plugin is released under the MIT License.
Feel free to customize this README according to the specific details and features of your pdf_toolkit Flutter plugin. Update the version numbers, usage examples, and API reference as needed.