PHP code example of sebastiansantillan / phpepub

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

    

sebastiansantillan / phpepub example snippets



PHPEpub\EpubBuilder;

$epub = new EpubBuilder();

$epub->setTitle('My First Book')
     ->setAuthor('Your Name')
     ->setLanguage('en')
     ->setDescription('A book description');

// Add chapters
$epub->addChapter('Chapter 1', '<h1>Chapter 1</h1><p>First chapter content...</p>');
$epub->addChapter('Chapter 2', '<h1>Chapter 2</h1><p>Second chapter content...</p>');

// Generate the EPUB file
$epub->save('my-book.epub');

$epub = new EpubBuilder();

$epub->setTitle('Accessible Book')
     ->setAuthor('Author Name')
     // Add accessibility metadata
     ->addAccessMode('textual')
     ->addAccessMode('visual')
     ->addAccessibilityFeature('structuralNavigation')
     ->addAccessibilityFeature('alternativeText')
     ->addAccessibilityHazard('none')
     ->setAccessibilitySummary('Fully accessible book with proper navigation and alt text')
     ->addConformsTo('EPUB Accessibility 1.1 - WCAG 2.1 Level AA');

$epub->addChapter('Chapter 1', '<h1>Accessible Chapter</h1><p>Content with proper structure...</p>');
$epub->save('accessible-book.epub');