A Flutter plugin for combining and manipulating PDF files. The plugin supports Android, iOS, Linux, MacOS and Web platforms and allows for merging multiple PDF files, creating PDFs from images, and extracting images from PDFs.
- Android: Uses the PDFBox library from Apache.
- iOS and macOS: PDF manipulation is done natively using Swift, with no external dependencies.
- Linux and Windows: Utilizes PDFium from Google, a C++ library.
- Web: Uses PDFLib in JavaScript for PDF manipulation.
Combine multiple PDF files into a single document.
Required Parameters:
inputPaths
: A list of strings representing the paths of the PDF files to be combined.outputPath
: A string representing the directory where the combined PDF should be saved.
MergeMultiplePDFResponse response = await PdfCombiner.mergeMultiplePDFs(
inputPaths: filesPath,
outputPath: outputDirPath,
);
if (response.status == PdfCombinerStatus.success) {
// response.response contains the output path as a String
// response.message contains a success message as a String
}
Convert a list of image files into a single PDF document.
Required Parameters:
inputPaths
: A list of strings representing the paths of the image files.outputPath
: A string representing the directory where the generated PDF should be saved.
Optional Parameters:
maxWidth
(default: 360): Maximum width for image compression.maxHeight
(default: 360): Maximum height for image compression.needImageCompressor
(default: true): Whether to compress the images.
PdfFromMultipleImageResponse response = await PdfCombiner.createPDFFromMultipleImages(
inputPaths: imagePaths,
outputPath: outputPath,
maxWidth: 480, // Optional
maxHeight: 640, // Optional
needImageCompressor: false, // Optional
);
if (response.status == PdfCombinerStatus.success) {
// response.response contains the output path as a String
// response.message contains a success message as a String
}
Extract images from a PDF file.
Required Parameters:
inputPath
: A string representing the file path of the PDF to extract images from.outputPath
: A string representing the directory where the extracted images should be saved.
Optional Parameters:
maxWidth
(default: 360): Maximum width for the extracted images.maxHeight
(default: 360): Maximum height for the extracted images.createOneImage
(default: true): Whether to create a single composite image from the PDF.
ImageFromPDFResponse response = await PdfCombiner.createImageFromPDF(
inputPath: pdfFilePath,
outputPath: outputPath,
maxWidth: 720, // Optional
maxHeight: 1080, // Optional
createOneImage: false, // Optional
);
if (response.status == PdfCombinerStatus.success) {
// response.response contains a list of output paths as List<String>
// response.message contains a success message as a String
}
This plugin works with file_picker
or image_picker
for selecting files. Ensure you handle permissions using permission_handler
before invoking the plugin.
The pdf_combiner
plugin does not directly use the following dependencies. They are mentioned only to guide the development of solutions that might require additional steps for file selection or permissions:
This plugin supports Android, iOS, Linux, macOS and web directly, no additional setup is required.
As of version 3.3.0 on the web: The
pdf_combiner.js
JavaScript file is now loaded dynamically, eliminating the need to manually include it and import it into the index.html file.
For versions older than 3.3.0, follow these steps:
-
Add the required JavaScript file
Download pdf_combiner.js and place it in theweb/assets/js
folder of your Flutter project. -
Include the script in your HTML file
Add the following line to the<head>
section of yourweb/index.html
file:<script src="assets/js/pdf_combiner.js"></script>
- No additional configuration is required for Android, iOS, or MacOS. Ensure the necessary dependencies for file selection and permissions are added to your project.
- Since version 3.3.0, the
pdf_combiner.js
script is automatically loaded in the web platform, making manual inclusion unnecessary for newer versions.