pdf_text 套件是 Flutter 插件,可在 Android 和 iOS 上實現從 PDF 文件讀取和提取文字內容。它將 PDF 頁面轉換為可讀字串,讓在 Flutter 應用中處理或顯示 PDF 文字變得輕鬆。此套件設計簡潔,具備跨平台相容性,可順暢整合至現有的 Flutter 專案。對於需要文字提取但無需完整渲染 PDF 的應用來說,這套件極為適合。
適用情境
從掃描的PDF中提取文字
建構文件搜尋功能
在應用中建立文字預覽
解析PDF內容以進行分析
支援無障礙功能
主要特色
跨平台支援(iOS 與 Android)
簡單文本提取 API
輕巧且快速
無需完整渲染PDF
適用於掃描和鍵入的PDF文件
適合對象
文件處理應用
教育工具
內容索引系統
可存取性增強
基於文本的搜尋實現
使用建議
僅限文字提取(無格式)
在處理掃描品質差或低品質的PDF檔案時可能遇到困難
不支援加密的PDF檔案
需要檔案路徑輸入以處理PDF
性能取決於PDF的大小和複雜性
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
PDF Text Plugin
This plugin for Flutter allows you to read the text content of PDF documents and convert it into strings. It works on iOS and Android. On iOS it uses Apple's PDFKit. On Android it uses Apache's PdfBox Android porting.
Getting Started
Add this to your package's pubspec.yaml file:
dependencies:pdf_text:^0.5.0
Usage
Import the package with:
import'package:pdf_text/pdf_text.dart';
Create a PDF document instance using a File object:
Optionally, you can delete the file of a document when you no longer need it.
This can be useful when you import a PDF document from outside the local
file system (e.g using a URL), since it is automatically stored in the temporary
directory of the app.
Delete the file of a single document:
doc.deleteFile();
or delete all the files of all the documents imported from outside the local
file system:
PDFDoc.deleteAllExternalFiles();
Functioning
This plugin applies lazy loading for the text contents of the pages. The text is cached page per page. When you request the text of a page for the first time, it is parsed and stored in memory, so that the second access will be faster. Anyway, the text of pages that are not requested is not loaded. This mechanism
allows you not to waste time loading text that you will probably not use. When you request the text content of the entire document, only the pages that have not been loaded yet are then loaded.
Public Methods
PDFDoc
Return
Description
PDFPage
pageAt(int pageNumber) Gets the page of the document at the given page number.
static Future<PDFDoc>
fromFile(File file, {String password = ""}) Creates a PDFDoc object with a File instance. Optionally, takes a password for encrypted PDF documents.
static Future<PDFDoc>
fromPath(String path, {String password = ""}) Creates a PDFDoc object with a file path. Optionally, takes a password for encrypted PDF documents.
static Future<PDFDoc>
fromURL(String url, {String password = ""}) Creates a PDFDoc object with a url. Optionally, takes a password for encrypted PDF documents.
void
deleteFile() Deletes the file related to this PDFDoc. Throws an exception if the FileSystemEntity cannot be deleted.
static Future
deleteAllExternalFiles() Deletes all the files of the documents that have been imported from outside the local file system (e.g. using fromURL).
Objects
classPDFDoc{
int length; // Number of pages of the documentList<PDFPage> pages; // Pages of the documentPDFDocInfo info; // Info of the documentFuture<String> text; // Text of the document
}
classPDFPage{
int number; // Number of the page in the documentFuture<String> text; // Text of the page
}
classPDFDocInfo{
String author; // Author string of the documentList<String> authors; // Authors of the documentDateTime creationDate; // Creation date of the documentDateTime modificationDate; // Modification date of the documentString creator; // Creator of the documentString producer; // Producer of the documentList<String> keywords; // Keywords of the documentString title; // Title of the documentString subject; // Subject of the document
}
Contribute
If you have any suggestions, improvements or issues, feel free to contribute to this project.
You can either submit a new issue or propose a pull request. Direct your pull requests into the dev branch.