Exemple #1
0
 /**
  * Use PHPMobi to dump a .mobi file.
  *
  * @return Response
  */
 private function produceMobi()
 {
     $mobi = new \MOBI();
     $content = new \MOBIFile();
     /*
      * Book metadata
      */
     $content->set('title', $this->title);
     $content->set('author', implode($this->authors));
     $content->set('subject', $this->title);
     /*
      * Front page
      */
     $content->appendParagraph($this->getExportInformation('PHPMobi'));
     if (file_exists($this->logoPath)) {
         $content->appendImage(imagecreatefrompng($this->logoPath));
     }
     $content->appendPageBreak();
     /*
      * Adding actual entries
      */
     foreach ($this->entries as $entry) {
         $content->appendChapterTitle($entry->getTitle());
         $content->appendParagraph($entry->getContent());
         $content->appendPageBreak();
     }
     $mobi->setContentProvider($content);
     // the browser inside Kindle Devices doesn't likes special caracters either, we limit to A-z/0-9
     $this->title = preg_replace('/[^A-Za-z0-9\\-]/', '', $this->title);
     return Response::create($mobi->toString(), 200, ['Accept-Ranges' => 'bytes', 'Content-Description' => 'File Transfer', 'Content-type' => 'application/x-mobipocket-ebook', 'Content-Disposition' => 'attachment; filename="' . $this->title . '.mobi"', 'Content-Transfer-Encoding' => 'binary']);
 }