pdf_text_extraction 1.2.0 copy "pdf_text_extraction: ^1.2.0" to clipboard
pdf_text_extraction: ^1.2.0 copied to clipboard

pdf_text_extraction

example/example.dart

// ignore: unused_shown_name
import 'dart:io' show Platform, Directory;
// ignore: unused_import
import 'package:ffi/ffi.dart';
import 'package:path/path.dart' as path;
import 'dart:ffi' as ffi;
import 'package:pdf_text_extraction/pdf_text_extraction.dart';

int logCallback(ffi.Pointer<ffi.Int8> msg) {
  print(nativeInt8ToString(msg));
  return 0;
}

const except = -1;
typedef dart_callback = int Function(ffi.Pointer<ffi.Int8>);
void main() {
  var libraryPath = path.join(Directory.current.path, 'TextExtraction.dll');
  if (Platform.isLinux) {
    libraryPath = path.join(Directory.current.path, 'TextExtraction.so');
  }
  final dylib = ffi.DynamicLibrary.open(libraryPath);

  var pdf = PDFTextExtractionBindings(dylib);
  var allocator = malloc;
  var uriPointer = stringToNativeInt8('1417.pdf', allocator: malloc);
  var pages = pdf.getPagesCount(uriPointer, ffi.nullptr);
  print('pages $pages');

  var result = pdf.extractText(
      uriPointer,
      0,
      -1,
      ffi.Pointer.fromFunction<
          ffi.Int32 Function(
        ffi.Pointer<ffi.Int8>,
      )>(logCallback, except));

  allocator.free(uriPointer);
  var text = nativeInt8ToString(result);
  if (text != '-1') {
    print('text: $text');
  } else {
    print('erro ao extrair testo');
  }
}
3
likes
110
pub points
67%
popularity

Publisher

unverified uploader

pdf_text_extraction

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

ffi, path

More

Packages that depend on pdf_text_extraction