PHP code example of metolabs / text-extractor-php

1. Go to this page and download the library: Download metolabs/text-extractor-php 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/ */

    

metolabs / text-extractor-php example snippets


use MetoLabs\TextExtractor\TextExtractor;

$text = TextExtractor::from('example.pdf');
echo $text;

$text = TextExtractor::from('example.png');

$extractor = TextExtractor::make('example.pdf', TextExtractor::MODE_TEXT);
$extractor->extract();
echo $extractor->getText();

use MetoLabs\TextExtractor\Configurations\PdfToImageConfiguration;
use MetoLabs\TextExtractor\Configurations\TesseractConfiguration;

$config = [
    'pdftoimage' => (new PdfToImageConfiguration())->setResolution(300),
    'tesseract' => (new TesseractConfiguration())->set('options', [
        'lang' => 'eng',
    ]),
];

$extractor = TextExtractor::make('example.pdf', TextExtractor::MODE_OCR, $config);
$extractor->extract();
echo $extractor->getText();

use MetoLabs\TextExtractor\Configurations\PdfToImageConfiguration;

$config = [
    'pdftoimage' => (new PdfToImageConfiguration())->setPages([1, 3, 5]),
];

$extractor = TextExtractor::make('example.pdf', TextExtractor::MODE_AUTO, $config);
$extractor->extract();
echo $extractor->getText();