1 <?php namespace BookStack\Http\Controllers;
3 use BookStack\Entities\ExportService;
4 use BookStack\Entities\Repos\ChapterRepo;
5 use BookStack\Exceptions\NotFoundException;
8 class ChapterExportController extends Controller
11 protected $chapterRepo;
12 protected $exportService;
15 * ChapterExportController constructor.
17 public function __construct(ChapterRepo $chapterRepo, ExportService $exportService)
19 $this->chapterRepo = $chapterRepo;
20 $this->exportService = $exportService;
21 parent::__construct();
25 * Exports a chapter to pdf.
26 * @throws NotFoundException
29 public function pdf(string $bookSlug, string $chapterSlug)
31 $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
32 $pdfContent = $this->exportService->chapterToPdf($chapter);
33 return $this->downloadResponse($pdfContent, $chapterSlug . '.pdf');
37 * Export a chapter to a self-contained HTML file.
38 * @throws NotFoundException
41 public function html(string $bookSlug, string $chapterSlug)
43 $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
44 $containedHtml = $this->exportService->chapterToContainedHtml($chapter);
45 return $this->downloadResponse($containedHtml, $chapterSlug . '.html');
49 * Export a chapter to a simple plaintext .txt file.
50 * @throws NotFoundException
52 public function plainText(string $bookSlug, string $chapterSlug)
54 $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
55 $chapterText = $this->exportService->chapterToPlainText($chapter);
56 return $this->downloadResponse($chapterText, $chapterSlug . '.txt');