1 <?php namespace BookStack\Http\Controllers;
3 use BookStack\Entities\Tools\ExportFormatter;
4 use BookStack\Entities\Repos\ChapterRepo;
5 use BookStack\Exceptions\NotFoundException;
8 class ChapterExportController extends Controller
11 protected $chapterRepo;
12 protected $exportFormatter;
15 * ChapterExportController constructor.
17 public function __construct(ChapterRepo $chapterRepo, ExportFormatter $exportFormatter)
19 $this->chapterRepo = $chapterRepo;
20 $this->exportFormatter = $exportFormatter;
24 * Exports a chapter to pdf.
25 * @throws NotFoundException
28 public function pdf(string $bookSlug, string $chapterSlug)
30 $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
31 $pdfContent = $this->exportFormatter->chapterToPdf($chapter);
32 return $this->downloadResponse($pdfContent, $chapterSlug . '.pdf');
36 * Export a chapter to a self-contained HTML file.
37 * @throws NotFoundException
40 public function html(string $bookSlug, string $chapterSlug)
42 $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
43 $containedHtml = $this->exportFormatter->chapterToContainedHtml($chapter);
44 return $this->downloadResponse($containedHtml, $chapterSlug . '.html');
48 * Export a chapter to a simple plaintext .txt file.
49 * @throws NotFoundException
51 public function plainText(string $bookSlug, string $chapterSlug)
53 $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
54 $chapterText = $this->exportFormatter->chapterToPlainText($chapter);
55 return $this->downloadResponse($chapterText, $chapterSlug . '.txt');