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.
Add this to your package's pubspec.yaml
file:
dependencies:
pdf_text: ^0.3.1
Import the package with:
import 'package:pdf_text/pdf_text.dart';
Create a PDF document instance using a File object:
PDFDoc doc = await PDFDoc.fromFile(file);
or using a path string:
PDFDoc doc = await PDFDoc.fromPath(path);
or using a URL string:
PDFDoc doc = await PDFDoc.fromURL(url);
Pass a password for encrypted PDF documents:
PDFDoc doc = await PDFDoc.fromFile(file, password: password);
Use faster initialization on Android:
PDFDoc doc = await PDFDoc.fromFile(file, fastInit: true);
Read the text of the entire document:
String docText = await doc.text;
Retrieve the number of pages of the document:
int numPages = doc.length;
Access a page of the document:
PDFPage page = doc.pageAt(pageNumber);
Read the text of a page of the document:
String pageText = await page.text;
Read the information of the document:
< 8000 div class="highlight highlight-source-dart notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="PDFDocInfo info = doc.info;">PDFDocInfo info = doc.info;