EBook::EPUB(3)
π EBook::EPUB π
okay so bestie, welcome to EBook::EPUB β the Perl module that literally generates EPUB documents for you. it's from the User Contributed Perl Documentation corner of the universe and it's lowkey iconic. β¨
β¨ NAME β¨
EBook::EPUB β module for generating EPUB documents π
πΈ VERSION πΈ
Version 0.6
π¦ SYNOPSIS π¦
here's the whole vibe, fr fr β no cap, this is the entire flow from "empty object" to "actual ebook file":
use EBook::EPUB;
# Create EPUB object
my $epub = EBook::EPUB->new;
# Set metadata: title/author/language/id
$epub->add_title('Three Men in a Boat');
$epub->add_author('Jerome K. Jerome');
$epub->add_language('en');
$epub->add_identifier('1440465908', 'ISBN');
# Add package content: stylesheet, font, xhtml and cover
$epub->copy_stylesheet('/path/to/style.css', 'style.css');
$epub->copy_file('/path/to/figure1.png',
'figure1.png', 'image/png');
$epub->encrypt_file('/path/to/CharisSILB.ttf',
'CharisSILB.ttf', 'application/x-font-ttf');
my $chapter_id = $epub->copy_xhtml('/path/to/page1.xhtml',
'page1.xhtml');
$epub->copy_xhtml('/path/to/notes.xhtml', 'notes.xhtml',
linear => 'no'
);
# Add top-level nav-point
my $navpoint = $epub->add_navpoint(
label => "Chapter 1",
id => $chapter_id,
content => 'page1.xhtml',
play_order => 1 # should always start with 1
);
# Add cover image
# Not actual epub standart but does the trick for iBooks
my $cover_id = $epub->copy_image('/path/to/cover.jpg', 'cover.jpg');
$epub->add_meta_item('cover', $cover_id);
# Generate resulting ebook
$epub->pack_zip('/path/to/three_men_in_a_boat.epub');
likeβ¦ look at that. she's doing it all. metadata, stylesheets, fonts, xhtml, nav points, a cover for iBooks, and then the whole thing gets zipped up into a real .epub. periodt. π
π SUBROUTINES/METHODS π
π the constructor
new([$params])β Create an EBook::EPUB object π«Ά
π metadata girlies
add_title($title)β Set the title of the book. yes, the actual name of the thing. you need this. πadd_identifier($id, [$scheme])β Set a unique identifier for the book, such as its ISBN or a URL. the$schemeis optional, but likeβ¦ specify it. it's giving organized. πadd_author($name, [$formal_name])β Add author of the document. for the deets, go checkadd_contributor. βοΈadd_creator($name, [fileas => $formal_name, role => $role])β Add primary creator or author of the publication of the publication. (yes, the original really says it twice, we love a dramatic entrance π) Seeadd_contributorfor details.add_contributor($name, [fileas => $formal_name, role =>])β Add person/organization that contributed to publication.$nameis the name in human-readable form, e.g."Arthur Conan Doyle",$formal_nameis in form, suitable for machine processing, e.g."Doyle, Arthur Conan".$rolereflects kind of contribution to document. See Section 2.2.6 of OPF specification for list of possible values: http://www.idpf.org/2007/opf/OPF_2.0_final_spec.html#Section2.2.6 πadd_coverage($coverage)β The extent or scope of the content of the resource. πΊοΈadd_date($date, [$event])β Date of publication, in the format defined by "Date and Time Formats" at http://www.w3.org/TR/NOTE-datetime and by ISO 8601 on which it is based. In particular, dates without times are represented in the formYYYY[-MM[-DD]]: a required 4-digit year, an optional 2-digit month, and if the month is given, an optional 2-digit day of month.$eventis an optional description of event that date refers to. Possible values may include:creation,publication, andmodification. πadd_description($description)β Add description of the publication content. spill the tea about what's inside. π΅add_format($format)β The media type or dimensions of the resource. Best practice is to use a value from a controlled vocabulary (e.g. MIME media types). πΎadd_language($lang)β Add language of the content of the publication.$langmust comply with RFC 3066 (see http://www.ietf.org/rfc/rfc3066.txt). πadd_publisher($publisher)β An entity responsible for making the resource available. π’add_relation($relation)β An identifier of an auxiliary resource and its relationship to the publication. πadd_rights($rights)β A statement about rights, or a reference to one. In this specification, the copyright notice and any further rights description should appear directly. βοΈadd_source($source)β Information regarding a prior resource from which the publication was derived. πadd_subject($subject)β Add subject of the publication. tag it, bestie. π·οΈadd_translator($name, [$formal_name])β Add translator of the document.$nameis in human-readable form, e.g."Arthur Conan Doyle",$formal_nameis in form, suitable for machine processing, e.g."Doyle, Arthur Conan". π«Άadd_type($type)βtypeincludes terms describing general categories, functions, genres, or aggregation levels for content. The advised best practice is to select a value from a controlled vocabulary. πadd_navpoint(%opts)β Add refrence to an OPS Content Document that is a part of publication.%optsis an anonymous hash, for possible key values seeEBook::EPUB::NCX::NavPoint. Method returns createdEBook::EPUB::NCX::NavPointobject that could be used later for adding subsections. π§add_meta_item($name, $value)β Add non-standard item to metadata e.g. metadata from source documetn that is not described in Doublin Core spec. (typos are part of the canon, we respect them π)
πΈ adding content by hand
add_xhtml($filename, $data, %opts)β Add xhtml data$datato$filenamein package. Returns id of newly added entry.%optsis an anonymous hash array of parameters:linearβ'yes'or'no'
add_stylesheet($filename, $data)β Add stylesheet data$dataas$filenamein package. Returns id of newly added entry. π¨add_image($filename, $data, $type)β Add image data$dataas$filenamein package with content type$type(e.g.image/jpeg). Returns id of newly added entry. πΌοΈ
π§ copying content from disk
copy_xhtml($source_file, $filename, %opts)β Add existing xhtml file$source_fileas$filenamein package. Returns id of newly added entry.%optsis an anonymous hash array of parameters:linearβ'yes'or'no'
copy_stylesheet($source_file, $filename)β Add existing css file$source_fileas$filenamein package. Returns id of newly added entry. πcopy_image($source_file, $filename, $type)β Add existing image file$source_fileas$filenamein package and set its content type to$type(e.g.image/jpeg). Returns id of newly added entry. πΈcopy_file($source_file, $filename, $type)β Add existing file$source_fileas$filenamein package and set its content type to$type(e.g.text/plain). Returns id of newly created entry. Returns id of newly added entry. (she said it twice, she's thorough π) πcopy_file($source_file, $filename, $type)β same energy as above, because that's literally how it's listed, and we don't skip entries in this house. π«‘encrypt_file($source_file, $filename, $type)β Add existing file$source_fileas$filenamein package and set its content type to$type(e.g.text/plain) Apply Adobe copy protection scheme to this file using book UUID as a key. Function croaks if key has not been set previously using. Returns id of newly added entry. π
β οΈ heads up bestie β encrypt_file will croak at you if the key hasn't been set previously using [the thing the original sentence trails off on]. the original text ends there, so that's exactly where we end too. no invented details, no cap.
pack_zip($filename)β Generate OCF Zip container with contents of current package. this is the finale, the main character moment, the actual file on disk. π
π AUTHOR π
Oleksandr Tymoshenko, <gonzo@bluezbox.com> π
π BUGS π
Please report any bugs or feature requests to <gonzo@bluezbox.com>. be nice, be specific, include the deets. π
βοΈ LICENSE AND COPYRIGHT βοΈ
Copyright 2009, 2010 Oleksandr Tymoshenko.
This module is free software; you can redistribute it and/or modify it under the terms of the BSD license. See the LICENSE file included with this distribution.
okay that's the whole page, bestie. you're officially fluent in EBook::EPUB. go make a book, you absolute icon. πβ¨
this lil tour was brought to you by perl v5.42.0, dated 2025-07-25 β and that's on EBook::EPUB(3). slay. π
π¦πΈ
π¦ where this page comes from
- fedora 43: perl-EBook-EPUB 0.6-39.fc43 Β· LicenseRef-Callaway-BSD
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms