PHP code example of intragile / php-text-extractor
1. Go to this page and download the library: Download intragile/php-text-extractor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
intragile / php-text-extractor example snippets
use IntrAgile\TextExtractor\TextExtractor;
$result = TextExtractor::create()->extract('/path/to/upload.docx');
if ($result->isSuccessful()) {
$index->store($result->text); // '' when the file simply has no text
} elseif ($result->isRetryable()) {
$queue->retryLater(); // timeout, missing tool, I/O error
} else {
$log->info($result->reason->value); // encrypted, corrupt, too_large, ...
}
$extractor = TextExtractor::create();
$extractor->extract('/tmp/php3hX9a'); // a path
$extractor->extract('/tmp/php3hX9a', 'export.csv'); // + original name for .csv/.md/.json/...
$extractor->extractFromString($bytes, 'notes.txt');
$extractor->extractFromStream($stream, 'report.pdf'); // read from the current position
use IntrAgile\TextExtractor\Contracts\Extractor;
use IntrAgile\TextExtractor\Format;
use IntrAgile\TextExtractor\Options;
use IntrAgile\TextExtractor\Result;
final class CloudOcrExtractor implements Extractor
{
public function supports(Format $format): bool
{
return $format->isImage();
}
public function extract(string $path, Format $format, Options $options): Result
{
return Result::extracted($this->client->recognise($path), $format);
}
}
$extractor = TextExtractor::create()->withExtractor(new CloudOcrExtractor($client));
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.