grandt / phpepub Goto Github PK
View Code? Open in Web Editor NEWPHP Classes for dynamically generating EPub files.
Home Page: http://www.phpclasses.org/package/6115
PHP Classes for dynamically generating EPub files.
Home Page: http://www.phpclasses.org/package/6115
It only show the last image when there is more than one Image in a Chapter.
Waiting for your response.
Thank you!
Hi
It should be Ok to remove composer.phar from your /legacy/ folder as most people have it separately installed these days. It causes problems in editors like phpStorm because composer.phar has declarations for some widely used Symfony components, so phpStorm reports duplicate class declarations unless you manually go and exclude each composer.phar from your project after each update.
Also, is it possible for you to tag a new release of grandt/relativepath so that composer will pick up that you have deleted composer.phar from there when including it as a dependency of grandt/phpepub?
thanks!
Generally, creating an epub from my html markup works just fine and this library is a HUGE time saver. Thank you so much for creating and maintaining it!
There is only problem I'm facing right now though: Whenever my original HTML markup contains an <img>
tag linking to a SVG file, adding it to a chapter fails (with EPub::EXTERNAL_REF_ADD
enabled, to embed all image files into the epub file). Adding any other image format like PNGs and JPEGs works as expected and if I disable EPub::EXTERNAL_REF_ADD
it works, too. I also tried adding other SVG files which still results in the error.
Here's the exact error message I'm facing:
PHP Warning: imagecreatefromstring(): Data is not in a recognized format in /Users/path/to/project/vendor/grandt/phpepub/src/PHPePub/Core/EPub.php on line 615
This is the markup related to the SVG I'm trying to convert:
<figure>
<img src="http://example.com/image.svg" alt="My svg image">
</figure>
Using the latest release with composer.
I needed to inherit EPub class to my custom classes, where I wanted to override addChapter with my own version. But since most of the variables are private, I think it would be a good idea to convert them to protected?
Right now, I cannot for instance in my inherited class access $this->isFinalized because that only belongs to EPub class.
Dear Asbjørn,
first of all, thanks for your excellent work.
I think I found a the reason, why it was not possible to assign a css-stylesheet to a toc.xhtml file.
In Line 1718 you use
$this->tocCSSFileName = $this->normalizeFileName($cssFileName);
instead of
$this->tocCssFileName = $this->normalizeFileName($cssFileName);
I don't know if this is the right way to inform you about bugs.
Anyway I hope you continue working on this class.
Kind regards,
Schorsch Roch
This issue still exists on the latest version 4.0.7.1
PHPePub is used by wallabag
During export articles in epub format i have :
Warnings in PHP log :
[Mon Nov 21 15:00:14.654739 2016] [:error] [pid 25654] [client IP:PORT] PHP Warning: file_exists(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/DIR_ALLOWED) in /DIR_INSTALL_WALLABAG/vendor/grandt/phpepub/src/PHPePub/Core/EPub.php on line 941
[Mon Nov 21 15:00:14.655128 2016] [:error] [pid 25654] [client IP:PORT] PHP Warning: is_file(): open_basedir restriction in effect. File(/var/www/heraut_eu/lou/www//) is not within the allowed path(s): (/DIR_ALLOWED) in /DIR_INSTALL_WALLABAG/vendor/phpzip/phpzip/src/Zip/Core/AbstractZipArchive.php on line 368
[Mon Nov 21 15:00:14.655281 2016] [:error] [pid 25654] [client IP:PORT] PHP Warning: file_exists(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/DIR_ALLOWED) in /DIR_INSTALL_WALLABAG/vendor/grandt/phpepub/src/PHPePub/Core/EPub.php on line 941
[Mon Nov 21 15:00:14.655396 2016] [:error] [pid 25654] [client IP:PORT] PHP Warning: file_exists(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/DIR_ALLOWED) in /DIR_INSTALL_WALLABAG/vendor/grandt/phpepub/src/PHPePub/Core/EPub.php on line 941
[Mon Nov 21 15:15:21.146524 2016] [:error] [pid 25655] [client IP:PORT] PHP Warning: file_exists(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/DIR_ALLOWED) in /DIR_INSTALL_WALLABAG/vendor/grandt/phpepub/src/PHPePub/Core/EPub.php on line 941
[Mon Nov 21 15:15:21.146917 2016] [:error] [pid 25655] [client IP:PORT] PHP Warning: is_file(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/DIR_ALLOWED) in /DIR_INSTALL_WALLABAG/vendor/phpzip/phpzip/src/Zip/Core/AbstractZipArchive.php on line 368
[Mon Nov 21 15:15:21.147072 2016] [:error] [pid 25655] [client IP:PORT] PHP Warning: file_exists(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/DIR_ALLOWED) in /DIR_INSTALL_WALLABAG/vendor/grandt/phpepub/src/PHPePub/Core/EPub.php on line 941
[Mon Nov 21 15:15:21.147171 2016] [:error] [pid 25655] [client IP:PORT] PHP Warning: file_exists(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/DIR_ALLOWED) in /DIR_INSTALL_WALLABAG/vendor/grandt/phpepub/src/PHPePub/Core/EPub.php on line 941
[Mon Nov 21 15:30:08.834828 2016] [:error] [pid 28756] [client IP:PORT] PHP Warning: file_exists(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/DIR_ALLOWED) in /DIR_INSTALL_WALLABAG/vendor/grandt/phpepub/src/PHPePub/Core/EPub.php on line 941
[Mon Nov 21 15:30:08.835217 2016] [:error] [pid 28756] [client IP:PORT] PHP Warning: is_file(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/DIR_ALLOWED) in /DIR_INSTALL_WALLABAG/vendor/phpzip/phpzip/src/Zip/Core/AbstractZipArchive.php on line 368
[Mon Nov 21 15:30:08.835384 2016] [:error] [pid 28756] [client IP:PORT] PHP Warning: file_exists(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/DIR_ALLOWED) in /DIR_INSTALL_WALLABAG/vendor/grandt/phpepub/src/PHPePub/Core/EPub.php on line 941
[Mon Nov 21 15:30:08.835508 2016] [:error] [pid 28756] [client IP:PORT] PHP Warning: file_exists(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/DIR_ALLOWED) in /DIR_INSTALL_WALLABAG/vendor/grandt/phpepub/src/PHPePub/Core/EPub.php on line 941
/DIR_INSTALL_WALLABAG : the install directory of my wallabag instance
/DIR_ALLOWED : two directoy allowed in allowed_paths configuration ( php.ini )
I have open a ticket in wallabag : wallabag/wallabag#2631
but wallabad is not directly concerned.
thanks
Hi
i'm actually using your PHPePub for a project
but the generate epub is a corupted file
do you have an idea of the reason of this corrupted file ?
any file i made is corrupted
thanks
Hello,
I would like to be able to add custom metafields in the opf.
More in particular I would like to be able to add :
This could be solved to add a function like epub->addCustomMeta which directly runs opf->addMeta.
Thanks in advance.
Hi, I came across with the problem of gif images being a jpeg file.
I've set isGifImagesEnabled to true. Still Gif images are becoming jpeg files so i've check the code and noticed that the $mime
only has png and jpeg conditions so i added the gif condition. Please see code below, the problem is the animation is gone.
`if ($mime == "image/png") {
imagealphablending($image_p, false);
imagesavealpha($image_p, true);
imagealphablending($image_o, true);
imagecopyresampled($image_p, $image_o, 0, 0, 0, 0, ($width*$ratio), ($height*$ratio), $width, $height);
ob_start();
imagepng($image_p, NULL, 9);
$image = ob_get_contents();
ob_end_clean();
$ext = "png";
}else if ($mime == "image/gif") {
imagealphablending($image_p, false);
imagesavealpha($image_p, true);
imagealphablending($image_o, true);
imagecopyresampled($image_p, $image_o, 0, 0, 0, 0, ($width*$ratio), ($height*$ratio), $width, $height);
ob_start();
imagepng($image_p, NULL, 9);
$image = ob_get_contents();
ob_end_clean();
$ext = "gif";
} else {
imagecopyresampled($image_p, $image_o, 0, 0, 0, 0, ($width*$ratio), ($height*$ratio), $width, $height);
ob_start();
imagejpeg($image_p, NULL, 80);
$image = ob_get_contents();
ob_end_clean();
$mime = "image/jpeg";
$ext = "jpg";
}`
Hi. Thanks for the fantastic package. Lovin' it!
Would you consider adding a composer.json and registering on packagist.org? It will help more people use your library, and help us stay up to date more easily. Thanks!
composer.json
{
"name": "grandt/phpepub",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"classmap": [ "" ]
}
}
I think more specific class names would really help with compatibility.
I've been trying to get around a name conflict (in the Omeka CMS, which also uses Item) using PHP's namespace
to no avail.
For some reason, it's putting together the various book parts but the spine and manifest are empty, producing a corrupt file.
I'm not sure the best way to approach this (nor am I sure I'm using namespaces correctly) but figured I'd put it out there as an issue.
Hi, I tried copying the function processChapterImages
and renamed it to processChapterAudio
with the exact code. I'm not that good in PHP so I didn't manage to change the variables because i fear I might do something wrong. Here is the code.
`protected function processChapterAudio(&$xmlDoc, $externalReferences = EPub::EXTERNAL_REF_ADD, $baseDir = "", $htmlDir = "", $backPath = "") {
if ($this->isFinalized || $externalReferences === EPub::EXTERNAL_REF_IGNORE) {
return FALSE;
}
// process img tags.
$postProcDomElememts = array();
$images = $xmlDoc->getElementsByTagName("source");
$itemCount = $images->length;
for ($idx = 0; $idx < $itemCount; $idx++) {
$img = $images->item($idx);
if ($externalReferences === EPub::EXTERNAL_REF_REMOVE_IMAGES) {
$postProcDomElememts[] = $img;
} else if ($externalReferences === EPub::EXTERNAL_REF_REPLACE_IMAGES) {
$altNode = $img->attributes->getNamedItem("alt");
$alt = "image";
if ($altNode !== NULL && strlen($altNode->nodeValue) > 0) {
$alt = $altNode->nodeValue;
}
$postProcDomElememts[] = array($img, $this->createDomFragment($xmlDoc, "[" . $alt . "]"));
} else {
$source = $img->attributes->getNamedItem("src")->nodeValue;
$parsedSource = parse_url($source);
$internalSrc = $this->sanitizeFileName(urldecode(pathinfo($parsedSource['path'], PATHINFO_BASENAME)));
$internalPath = "";
$isSourceExternal = FALSE;
if ($this->resolveMedia($source, $internalPath, $internalSrc, $isSourceExternal, $baseDir, $htmlDir, $backPath)) {
$img->setAttribute("src", $backPath . $internalPath);
} else if ($isSourceExternal) {
$postProcDomElememts[] = $img; // External image is missing
} // else do nothing, if the image is local, and missing, assume it's been generated.
}
}`
Its actually the same with the processChapterImages
function the only difference is I am looking for the source
tag and not the img
tag and I used the resolveMedia
to replace the src
of all the media files.
It replaces the src
but it did not download the file. I did not change anything in the resolveMedia
function. File source is in here : http://www.noiseaddicts.com/samples/280.mp3
Hi Grandt,
I think downloading images from an https protocol is not allowed? i've tried downloading the same image from an https site and an http site. The image is downloaded from the http site, but the image fails to download from the https site.
I exported two articles containing a lot of different pictures and some of them seem to not return any information through pathinfo, leading to failure.
Therefore, pathinfo($internalSrc);
returns undefined here. It should be tested before next conditional.
in EPub::finalize()
$this->opf->addMeta("cover", "coverImage");
should be
$this->opf->addMeta("cover", "CoverImage");
to match the call
$this->addFile($imgPath, "CoverImage", $imageData, $mimetype);
in setCoverImage()
?
Hi,
I generated an epub version of a drupal node through the print module. The epub does not open in iBook and does not validate correctly.
“This page contains the following errors:
error on line 21 at column 27: AttValue: " or ' expected
Below is a rendering of the page up to the first error.”
A similar issue has been filed with the drupal issue queue https://www.drupal.org/node/2147659 but was closed and the author was redirected here.
Let's say I want to create an ebook with the title containing a |, like « some text | some text », and a chapter with the same name.
The table of contents is linking to my chapter as some text | some text.html
, but the html file created (corresponding to the chapter) is named some text _ some text.html
. So I can't access my first chapter.
I'm currently putting PHPePub into wallabag, and without this issue, it works great.
I'm having difficulty creating a valid EPUB3 file due to missing landmarks in the generated epub3toc.xhtml file.
The Cover and TOC are added, but I don't know how to define my colophon, preface, forward, etc. This is a big problem for generating iBooks-valid ePub files.
How can i change the languge.
Hello, I can't find a way with the library to add a file in the META-INF folder (I'm trying to add com.apple.ibooks.display-options.xml to be able to force embed font in apple pub reading software).
Is there a way to do it ?
For the moment, I'm using the ZipArchive php class and add it after my pub generation.
Hello team,
I got this error, how can I fix it :(?
when I check in line 383,
381: $ids = $this->findIdAttributes($chapterData);
382: foreach ($ids as $id) {
383: $item->addIndexPoint($id);
}
When i try dump $ids, normal got empty $ids, error show $ids has one element with string as value
Can you check it?
Thanks,
Hello!
I think, it could be good to display the alt value of images instead of simply removing entire tag.
It can be done with this regexp for example:
$html_content = preg_replace('/<\s*?img.*alt="(.*?)".*?>/', '${1}', $html_content);
I'll use this regular expression in my epub plugin for the Leed RSS reader and I think, it can be usefull for you too.
Thanks for your great work on PHPePub !
Hi i am having this error when i am trying to put this line of code for every page in the chapter
the code is <span epub:type='pagebreak' id='page1' title='1' />
This gives me an error
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Namespace prefix epub for type on span is not defined in Entity, line: 165 in C:\wamp\www\Dropbox\Audra\Basic Editor\Beta 1.0\basiceditor\lib_epub\EPub.php on line 699
This maybe something I'm doing wrong, but I can't seem to figure it out. I'm using the following code to create a new epub file. I need to add the Table of Contents after the cover page but before the rest of the book. Instead I'm getting the whole book THEN the TOC.
Can you help? Thanks.
function epub_generate_rss($blogurl, $authorname = false) {
$book = new EPub();
$book->setTitle("test");
if (!$authorname)
$authorname = "Ima Author";
$book->setAuthor($authorname, $authorname);
$book->setIdentifier($blogurl . "&stamp=" . time(), EPub::IDENTIFIER_URI);
$book->setLanguage("en");
$book->addCSSFile("styles.css", "css1", $epub_css);
$cover = $epub_content_start . "<h1>" . $feed->get_title() . "</h1>\n";
if ($authorname)
$cover .= "<h2>By: $authorname</h2>\n";
$cover .= "<h2>From: <a href=\"$blogurl\">$blogurl</a></h2>";
$cover .= $epub_content_end;
$book->addChapter("Notices", "Cover.html", $cover);
$book->buildTOC();
$book->addChapter(
"Test",
"Chapter1.html",
$epub_content_start . "<h1Test Title</h1>\nPlenty of test content" . $epub_content_end
);
}
return $book;
}
Hello,
I can create an epub and it's opening without any problem in Calibre and also in a Sony Reader. However, if I try to open it with Adobe Digital Editions it says that the file is corrupted.
Is there anything I should take into account to solve the issue?
Thank you!
Can I convert PDF to EPUB using the library?
Currently, PHPePub is creating epub archives that mirror the file server path for retrieved image.
E.g. OEBPS/images/http/example.com/wp-content/uploads/2016/10/07/image.png
How I force it to be "OEBPS/images/image.png"?
I need to create pages that appear in the file manifest, but not the table of contents. Does PHPePub support this or will I have to hack it?
in your class in line #533 and #428 you're using $basedir which is not declared and should be $baseDir :-)
Hi,
wallabag uses PHPePub to produce epubs from articles.
We first add a custom cover as a chapter, then we're looping around our entries to produce a chapter for each entry.
However, it seems the produced epub has it's first two chapters with the same id (1) in the book.opf file. Therefore, our first entry isn't shown since it has the same id as our cover.
A workaround is to set $this->chapterCount
to 1, but I can't get to understand why this happens.
Is there a way i can encrypt the created epub with a password before someone can open the zip file
The PHP each() function is deprecated in PHP 7.2
There is an easy migration path with foreach.
I am using PHP 7.2 und I'd like to use your library without any deprecation warnings. Please update your source code.
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.