PHP code example of shipfastlabs / parsel
1. Go to this page and download the library: Download shipfastlabs/parsel 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/ */
shipfastlabs / parsel example snippets
use Shipfastlabs\Parsel;
$text = Parsel::file('invoice.pdf')->text();
$document = Parsel::file('invoice.pdf')
->pageRange(1, 5)
->withOcr(language: 'eng')
->withDpi(300)
->parse();
foreach ($document->pages as $page) {
foreach ($page->items as $item) {
echo "{$item->text} @ ({$item->x}, {$item->y})\n";
}
}
use Shipfastlabs\Parsel;
$text = Parsel::file('/path/to/report.pdf')->text();
$document = Parsel::bytes($uploadedBytes, 'pdf')->parse();
$text = Parsel::file('contract.docx')->text();
$rows = Parsel::file('report.xlsx')->text();
$slides = Parsel::file('deck.pptx')->text();
$scan = Parsel::file('receipt.png')
->withOcr()
->text();
$photo = Parsel::file('invoice.jpg')
->withOcr(language: 'eng')
->parse();
$text = Parsel::file('document.pdf')
->withoutOcr()
->text();
$document = Parsel::file('document.pdf')->parse();
echo $document->text;
echo $document->pageCount();
foreach ($document->pages as $page) {
foreach ($page->items as $item) {
echo $item->text;
}
}
$array = Parsel::file('document.pdf')->toArray();
Parsel::file('document.pdf')->page(7);
Parsel::file('document.pdf')->pages(1, 3, 5);
Parsel::file('document.pdf')->pages('1-5', 10);
Parsel::file('document.pdf')->pageRange(1, 5);
Parsel::file('document.pdf')->pageRange(1, 5)->page(10);
Parsel::file('document.pdf')->maxPages(50)->text();
$text = Parsel::file('scan.pdf')->withOcr()->text();
$text = Parsel::file('scan.pdf')
->withOcr(
language: 'fra',
tessdataPath: '/usr/share/tessdata',
serverUrl: 'http://localhost:8828/ocr',
workers: 8,
)
->text();
$text = Parsel::file('document.pdf')->withoutOcr()->text();
Parsel::file('document.pdf')->withDpi(300);
Parsel::file('document.pdf')->preserveSmallText();
Parsel::file('secret.pdf')->withPassword('hunter2');
Parsel::file('document.pdf')->withBinary('/usr/local/bin/lit');
Parsel::file('document.pdf')->withTimeout(120);
Parsel::file('document.pdf')->option('some-new-flag');
Parsel::file('document.pdf')->option('some-new-flag', 42);
Parsel::file('document.pdf')->save('document.txt');
Parsel::file('document.pdf')->save('document.json');
$screenshots = Parsel::file('document.pdf')
->pageRange(1, 5)
->screenshots('/tmp/parsel-pages');
foreach (Parsel::file('large-document.pdf')->lazyPages() as $page) {
foreach ($page->items as $item) {
// Process one page at a time...
}
}
$document->text;
$document->metadata;
$document->pages;
$document->pageCount();
$page->number;
$page->width;
$page->height;
$page->text;
$page->items;
$item->text;
$item->x;
$item->y;
$item->width;
$item->height;
$item->fontName;
$item->fontSize;
$item->confidence;
Parsel::usingBinary('/usr/local/bin/lit');
Parsel::defaultTimeout(120);
use Shipfastlabs\Parsel;
$fake = Parsel::fake([
'--format json' => file_get_contents(__DIR__.'/fixtures/lit-output.json'),
]);
$document = Parsel::file('invoice.pdf')->parse();
expect($fake->recordedCommands()[0])->toContain('--format', 'json');