mjohann / paginated-file-reader
A PHP library to read files page by page, supporting multiple formats like TXT, PDF, DOCX, and ODT. Each file type is handled by a dedicated reader class, all following a unified interface for seamless integration.
v1.0.0
2025-04-13 17:38 UTC
Requires
- php: ^8.0
- phpoffice/phpword: ^1.3
- smalot/pdfparser: ^2.12
README
A PHP library to read files page by page, supporting multiple formats like TXT, PDF, DOCX, and ODT. Each file type is handled by a dedicated reader class, all following a unified interface for seamless integration.
π¦ Installation
You can install the library via Composer:
composer require mjohann/paginated-file-reader
βοΈ Requirements
- PHP 8.0 or higher
π Features
- Read files page by page (pagination logic varies by file type)
- Supported formats:
.txt
and.md
(50 lines per page).pdf
(usingsmalot/pdfparser
).docx
(usingphpoffice/phpword
).odt
(using nativeZipArchive
)
- Easily extendable for other file types
- Unified interface for all readers
π§ͺ Usage Example
<?php require 'vendor/autoload.php'; use MJohann\Packlib\PaginatedFileReader; $reader = new PaginatedFileReader('path/to/your/file.pdf'); // Read page 0 echo $reader->readPage(0); // Get total pages echo $reader->getTotalPages();
For more examples, see the example/script.php
file in the repository.
π Project Structure
project/
βββ src/
β βββ Interfaces/
β β βββ PaginatedFileReaderInterface.php
β βββ Readers/
β β βββ TextFileReader.php
β β βββ PdfFileReader.php
β β βββ DocxFileReader.php
β β βββ OdtFileReader.php
β βββ PaginatedFileReader.php
βββ example/
β βββ script.php
βββ composer.json
βββ .gitignore
βββ LICENSE
βββ README.md
π License
This project is licensed under the MIT License. See the LICENSE file for more information.
π¨βπ» Author
Developed by Matheus Johann AraΓΊjo β Pernambuco, Brazil.