pdf_merger 是一個 Flutter 插件,可在 Android 與 iOS 平台上將多個 PDF 檔案合併為單一文件。它提供簡單的 API,可程式化地合併 PDF 檔案,非常適合需要文件整合的應用程式。如範例所示,使用者必須授與檔案權限並整合檔案選擇器後才能使用此套件。該套件輕量且專為與現有 Flutter 項目無縫整合而設計。
適用情境
從用戶選擇合併多個PDF
將報告或表單合併為一個檔案
支援文件處理工作流程
建立合併的PDF以分享
在應用程式中自動聚合PDF
啟用離線PDF管理
主要特色
跨平台支援(Android 與 iOS)
簡單合併 API
與檔案選擇器整合相容
輕便高效
支援 PDF 檔案清單
輕鬆設定,文件清楚
適合對象
文件管理應用
教育工具
商業報告應用
表單和提交系統
PDF 處理工具
需要PDF合併的行動應用程式
使用建議
需要檔案權限處理
需要外部文件選擇器整合
僅限合併,無法編輯PDF
無內建預覽功能
依賴於範例程式碼中的正確設定
不適用於大規模PDF操作
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
pdf_merger
A new Flutter plugin for merge List of PDF files. It supports both android and IOS. Before call this package make sure you allow permission and file picker see example.
Also check file_picker and permission handle to implement before calling the plugin.
PDF merger method
Merge Multiple PDF
//paths is a list of paths, example List<String> allSelectedFilePath. //outputDirPath is output path with filename, exmaple /user/android/download/ABC.pdfMergeMultiplePDFResponse response = awaitPdfMerger.mergeMultiplePDF(paths: filesPath, outputDirPath: outputDirPath);
if(response.status == "success") {
//response.response for output path in String//response.message for success message in String
}
Create PDF From Multiple Image
//paths is a list of paths, example List<String> allSelectedFilePath. //outputDirPath is output path with filename, exmaple /user/android/download/ABC.pdf//Optional params maxWidth : defalut set to 360, maxHeight : defalut set to 360, needImageCompressor : default set to true.CreatePDFFromMultipleImageResponse response = PdfMerger.createPDFFromMultipleImage(paths: filesPath, outputDirPath: outputDirPath);
if(response.status == "success") {
//response.response for output path in String//response.message for success message in String
}
Create Image From PDF
//paths selected file path (String). Example user/android.downlaod/MYPDF.pdf//outputDirPath is output path with filename, exmaple /user/android/download/ABC.pdf//Optional params maxWidth : defalut set to 360, maxHeight : defalut set to 360, createOneImage : default set to true.CreateImageFromPDFResponse response = awaitPdfMerger.createImageFromPDF(path: singleFile, outputDirPath: outputDirPath);
if(response.status == "success") {
//response.response for output path in List<String>//response.message for success message in String
}
Get File Size
//paths selected file path (String). Example user/android.downlaod/MYPDF.pdfSizeFormPathResponse response = awaitPdfMerger.sizeFormPath(path: singleFile);
if(response.status == "success") {
//response.response for size of file//response.message for success message in String
}
Build Info
BuildInfoResponse response = awaitPdfMerger.buildInfo();
Get.snackbar("Info", "App Name : " + response.appName + "\n" +
"Build Number : " + response.buildDate + "\n" +
"Build Number with Time : " + response.buildDateWithTime + "\n" +
"Package Name : " + response.packageName + "\n" +
"Version Number : " + response.versionNumber + "\n" +
"Build Number : " + response.buildNumber.toString() );
Android & IOS
Usage
See Example. Use with file picker and add permission handler before calling pdf_merger. Make sure to call permission handler for write permission before call pdf_merger.
file_picker
https://pub.dev/packages/file_picker
permission_handler
https://pub.dev/packages/permission_handler
Support
Android & IOS
For Android
Add these lines in your progaurd
//required to prevent errors from the spongycastle libraries
-keep classorg.spongycastle.** { *; }
-dontwarn org.spongycastle.**