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

This package is auto-updated.

Last update: 2025-04-14 18:17:25 UTC


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 (using smalot/pdfparser)
    • .docx (using phpoffice/phpword)
    • .odt (using native ZipArchive)
  • 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.