3 namespace BookStack\Http\Controllers;
5 use BookStack\Entities\ExportService;
6 use BookStack\Entities\Repos\EntityRepo;
7 use BookStack\Exceptions\NotFoundException;
8 use Illuminate\Http\Response;
11 class ChapterExportController extends Controller
16 protected $entityRepo;
21 protected $exportService;
24 * ChapterExportController constructor.
25 * @param EntityRepo $entityRepo
26 * @param ExportService $exportService
28 public function __construct(EntityRepo $entityRepo, ExportService $exportService)
30 $this->entityRepo = $entityRepo;
31 $this->exportService = $exportService;
32 parent::__construct();
36 * Exports a chapter to pdf .
37 * @param string $bookSlug
38 * @param string $chapterSlug
40 * @throws NotFoundException
43 public function pdf(string $bookSlug, string $chapterSlug)
45 $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
46 $pdfContent = $this->exportService->chapterToPdf($chapter);
47 return $this->downloadResponse($pdfContent, $chapterSlug . '.pdf');
51 * Export a chapter to a self-contained HTML file.
52 * @param string $bookSlug
53 * @param string $chapterSlug
55 * @throws NotFoundException
58 public function html(string $bookSlug, string $chapterSlug)
60 $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
61 $containedHtml = $this->exportService->chapterToContainedHtml($chapter);
62 return $this->downloadResponse($containedHtml, $chapterSlug . '.html');
66 * Export a chapter to a simple plaintext .txt file.
67 * @param string $bookSlug
68 * @param string $chapterSlug
70 * @throws NotFoundException
72 public function plainText(string $bookSlug, string $chapterSlug)
74 $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
75 $chapterText = $this->exportService->chapterToPlainText($chapter);
76 return $this->downloadResponse($chapterText, $chapterSlug . '.txt');