extractText static method

Future<String> extractText({
  1. String? filePath,
  2. Uint8List? bytes,
  3. String? url,
  4. String password = "",
  5. int startPage = 0,
  6. int endPage = -1,
})

Implementation

static Future<String> extractText({String? filePath, Uint8List? bytes, String? url, String password = "", int startPage = 0, int endPage = -1}) async {
  final UPdfDocument document = await UPdfDocument.open(path: filePath, bytes: bytes, url: url, password: password);
  final UPdfPageRenderer renderer = UPdfPageRenderer(document);
  final StringBuffer buffer = StringBuffer();
  final int last = endPage < 0 ? document.pageCount : endPage;
  for (int i = startPage; i < last && i < document.pageCount; i++) {
    final UPdfPage? page = await document.page(i);
    if (page == null) continue;
    buffer.writeln((await renderer.extractText(page)).text);
  }
  await document.close();
  return buffer.toString();
}