tekkcraft/epub-generator
Composer 安装命令:
composer require tekkcraft/epub-generator
包简介
Generate EPUB files
README 文档
README
A simple library to generate EPUB files.
Usage
$coverImage = new \Tekkcraft\EpubGenerator\EpubAsset('path/to/image-folder', 'cover.png', 'image/png'); $generator = new \Tekkcraft\EpubGenerator\EpubDocument('book', 'TekkCraft', 'unique-book-name', '/path/to/storage-directory', $coverImage); $css = new EpubAsset( 'path/to/css-folder', 'epub.css', 'text/css', ); $generator->addCss($css); $sectionOne = new \Tekkcraft\EpubGenerator\EpubSection( 'section1', 'Section 1', '<h1>Chapter 1</h1><p class="some-css-class">This is the content of Chapter 1.</p>', ); $generator->addSection($sectionOne); $image = new \Tekkcraft\EpubGenerator\EpubAsset('path/to/image-folder', 'image.png', 'image/png'); $generator->addImage($image); $sectionTwo = new \Tekkcraft\EpubGenerator\EpubSection( 'section2', 'Section 2', '<h1>Chapter 2</h1><p>This is the content of Chapter 2.</p><img src="../img/image.png" />', ); $generator->addSection($sectionTwo); $epubFile = $generator->generateEpub();
This would create a new EPUB file named book.epub in the directory /path/to/storage-directory.
The $epubFile contains the file name of the generated EPUB.
All images are saved in the img folder and can be accessed using img/image-name.png.
All CSS assets are saved in the css folder and can be accessed using css/file-name.css.
All sections will be saved into the xhtml directory, meaning if you want to reference an image from one of your
sections, you will need to call it in your HTML using ../img/my-image.png.
Required headers for download
If you want to provide your EPUB file as a download, add these headers:
header('Content-Type: application/epub+zip'); header(sprintf('Content-Disposition: attachment; filename="%s.epub"', 'my-ebook')); header(sprintf('Content-Length: %s', strlen($epubFile)));
Validating an EPUB file
To validate an epub file, you can use the epubcheck tool provided by w3c.
I did not include this in my repository as it is a .jar file and therefore needs Java to run.
In addition to that, you will probably have to use PHP's exec() function to call it, which is generally unsafe.
(It is, however downloaded when running the test suite, as this should not happen on a production system)
Testing
In order to run the PHPUnit test suite you will need to have java installed on your system in order to use
the epubcheck.jar.
The epubcheck.jar will be downloaded from https://github.com/w3c/epubcheck and
saved into the sys_get_temp_dir() on first test execution.
tekkcraft/epub-generator 适用场景与选型建议
tekkcraft/epub-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 10 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tekkcraft/epub-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tekkcraft/epub-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-21