PHP code example of casonwebdev / pdf-to-text

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

    

casonwebdev / pdf-to-text example snippets


use Spatie\PdfToText\Pdf;

echo Pdf::getText('book.pdf'); //returns the text from the pdf

$text = (new Pdf())
    ->setPdf('book.pdf')
    ->text();

echo Pdf::getText('book.pdf');

$text = (new Pdf('/custom/path/to/pdftotext'))
    ->setPdf('book.pdf')
    ->text();

echo Pdf::getText('book.pdf', '/custom/path/to/pdftotext');

$text = (new Pdf())
    ->setPdf('table.pdf')
    ->setOptions(['layout', 'r 96'])
    ->text()
;

echo Pdf::getText('book.pdf', null, ['layout', 'opw myP1$$Word']);

 $text = (new Pdf())
     ->setPdf('table.pdf')
     ->setOptions(['layout', 'r 96'])
     ->addOptions(['f 1'])
     ->text()
 ;
 
bash
which pdftotext