extractTextAsXML method

String extractTextAsXML(
  1. String inputPdfFilePath, {
  2. int startPage = 0,
  3. int endPage = -1,
  4. Allocator allocator = calloc,
})

Implementation

String extractTextAsXML(String inputPdfFilePath,
    {int startPage = 0, int endPage = -1, ffi.Allocator allocator = calloc}) {
  var uriPointer = stringToNativeInt8(inputPdfFilePath, allocator: allocator);
  try {
    var result = pdfTextExtractionBindings!.extractTextAsXML(
        uriPointer,
        startPage,
        endPage,
        ffi.Pointer.fromFunction<
            ffi.Int32 Function(
          ffi.Pointer<ffi.Int8>,
        )>(_logCallback, except));

    var text = nativeInt8ToString(result);
    if (text != '-1') {
      return text;
    } else {
      throw Exception('Error extracting text from PDF: $_lastError');
    }
  } catch (e) {
    rethrow;
  } finally {
    allocator.free(uriPointer);
  }
}