addCSSFile() public method

Add a CSS file to the book.
public addCSSFile ( string $fileName, string $fileId, string $fileData, integer $externalReferences = EPub::EXTERNAL_REF_IGNORE, string $baseDir = "" ) : boolean
$fileName string Filename to use for the CSS file, must be unique for the book.
$fileId string Unique identifier for the file.
$fileData string CSS data
$externalReferences integer How to handle external references, EPub::EXTERNAL_REF_IGNORE, EPub::EXTERNAL_REF_ADD or EPub::EXTERNAL_REF_REMOVE_IMAGES? See documentation for processCSSExternalReferences for explanation. Default is EPub::EXTERNAL_REF_IGNORE.
$baseDir string Default is "", meaning it is pointing to the document root. NOT used if $externalReferences is set to EPub::EXTERNAL_REF_IGNORE.
return boolean $success
Beispiel #1
0
$book->setDate(time());
// Strictly not needed as the book date defaults to time().
$book->setRights("Copyright and licence information specific for the book.");
// As this is generated, this _could_ contain the name or licence information of the user who purchased the book, if needed. If this is used that way, the identifier must also be made unique for the book.
$book->setSourceURL("http://JohnJaneDoePublications.com/books/TestBook.html");
$book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP");
$book->setSubject("Test book");
$book->setSubject("keywords");
$book->setSubject("Chapter levels");
// Insert custom meta data to the book, in this cvase, Calibre series index information.
$book->addCustomMetadata("calibre:series", "PHPePub Test books");
$book->addCustomMetadata("calibre:series_index", "1");
$log->logLine("Set up parameters");
$cssData = "body {\n  margin-left: .5em;\n  margin-right: .5em;\n  text-align: justify;\n}\n\np {\n  font-family: serif;\n  font-size: 10pt;\n  text-align: justify;\n  text-indent: 1em;\n  margin-top: 0px;\n  margin-bottom: 1ex;\n}\n\nh1, h2 {\n  font-family: sans-serif;\n  font-style: italic;\n  text-align: center;\n  background-color: #6b879c;\n  color: white;\n  width: 100%;\n}\n\nh1 {\n    margin-bottom: 2px;\n}\n\nh2 {\n    margin-top: -2px;\n    margin-bottom: 2px;\n}\n";
$log->logLine("Add css");
$book->addCSSFile("styles.css", "css1", $cssData);
// This test requires you have an image, change "demo/cover-image.jpg" to match your location.
$log->logLine("Add Cover Image");
$book->setCoverImage("Cover.jpg", file_get_contents("demo/cover-image.jpg"), "image/jpeg");
// A better way is to let EPub handle the image itself, as it may need resizing. Most e-books are only about 600x800
//  pixels, adding mega-pixel images is a waste of place and spends bandwidth. setCoverImage can resize the image.
//  When using this method, the given image path must be the absolute path from the servers Document root.
/* $book->setCoverImage("/absolute/path/to/demo/cover-image.jpg"); */
// setCoverImage can only be called once per book, but can be called at any point in the book creation.
$log->logLine("Set Cover Image");
$cover = $content_start . "<h1>Test Book</h1>\n<h2>By: John Doe Johnson</h2>\n" . $bookEnd;
$book->addChapter("Notices", "Cover.html", $cover);
$book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE);
//    function buildTOC($cssFileName = NULL, $tocCSSClass = "toc", $title = "Table of Contents", $addReferences = TRUE, $addToIndex = FALSE, $tocFileName = "TOC.xhtml") {
$book->addFileToMETAINF("com.apple.ibooks.display-options.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<display_options>\n    <platform name=\"*\">\n        <option name=\"fixed-layout\">true</option>\n        <option name=\"interactive\">true</option>\n        <option name=\"specified-fonts\">true</option>\n    </platform>\n</display_options>");
// add a custom metadata to use on the MetaValue entries.