A PDF manipulator based on pdftk.
PHPExtractor is a PDF manipulation tool for PHP.
- Concatenate pages from several PDF files into a new PDF file
- Split a PDF into multiple one page PDF files
- Convert PDF to text
- Search PDF
- Rebuild PDF by keyword(s)
- Extract PDF by keyword(s)
- Create new directory
- Delete all files from directory
- The
pdftk
command must be installed on your system
You should use use composer to install this library.
composer require ztomesic/pdfextractor
use ZTomesic\PDFExtractor\PDFExtractor;
use ZTomesic\PDFExtractor\PDF;
$pdf = new PDF('/file/location/file.pdf');
Split a PDF file into one file per page.
$file = new PDF('/file/location/file.pdf');
PDFExtractor::burst($file)->save('/location/where/to/burst/');
Concatenate pages from several PDF files into a new PDF file.
PDFExtractor::cat(/location/of/pdf/files/, '*.pdf')->save('location/where/to/save/', 'name_of_new_file.pdf');
Convert PDF to text.
$pdf = new PDF('/file/location/file.pdf');
PDFExtractor::PDFToText($pdf);
Search PDF file by keywoard(s).
$pdf = new PDF('/file/location/file.pdf');
PDFExtractor::searchPDF($pdf, 'wordToSearchBy');
Rebuild PDF(s) by keyword(s)
$pdf = new PDF('/file/location/file.pdf');
PDFExtractor::rebuildPDFByKeyword($pdf, '/location/where/to/burst/', '/location/where/to/rebuild/', 'keyword_to_rebuild_by');
Change location of specific file
$pdf = new PDF('/file/location/file.pdf');
PDFExtractor::relocateFile($pdf, '/new/file/path/');
Delete all content from folder.
$excludedFiles = ['excluded_file.pdf'];
PDFExtractor::clearFolder('/path/to/directory/', $excludedFiles);
Delete directory and content.
PDFExtractor::removeDirectory('/path/to/directory/');
Create new directory.
PDFExtractor::createDirectory('/path/to/directory/name/');
Search PDF(s) and rebuild by keyword.
$pdf = new PDF('/file/location/file.pdf');
$PDFExtractor = PDFExtractor::burst($file)->save('/location/where/to/burst/');
$PDFExtractor->searchMultiplePDFByKeywords('/location/where/to/burst/', 'wordToSearchBy')
->changeFileLocation('/location/where/to/rebuild/')
->mergePDFByKeywords();
Extract metadata to array.
PDFExtractor::extractMetadata('/path/to/directory/name/')
->save('/location/where/to/save/', 'name_of_file.txt')
->toArray();
Extract metadata to string.
PDFExtractor::extractMetadata('/path/to/directory/name/')
->save('/location/where/to/save/', 'name_of_file.txt')
->toString();