3 namespace BookStack\Exports\Controllers;
5 use BookStack\Entities\Queries\ChapterQueries;
6 use BookStack\Exceptions\NotFoundException;
7 use BookStack\Exports\ExportFormatter;
8 use BookStack\Http\Controller;
11 class ChapterExportController extends Controller
13 public function __construct(
14 protected ChapterQueries $queries,
15 protected ExportFormatter $exportFormatter,
17 $this->middleware('can:content-export');
21 * Exports a chapter to pdf.
23 * @throws NotFoundException
26 public function pdf(string $bookSlug, string $chapterSlug)
28 $chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
29 $pdfContent = $this->exportFormatter->chapterToPdf($chapter);
31 return $this->download()->directly($pdfContent, $chapterSlug . '.pdf');
35 * Export a chapter to a self-contained HTML file.
37 * @throws NotFoundException
40 public function html(string $bookSlug, string $chapterSlug)
42 $chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
43 $containedHtml = $this->exportFormatter->chapterToContainedHtml($chapter);
45 return $this->download()->directly($containedHtml, $chapterSlug . '.html');
49 * Export a chapter to a simple plaintext .txt file.
51 * @throws NotFoundException
53 public function plainText(string $bookSlug, string $chapterSlug)
55 $chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
56 $chapterText = $this->exportFormatter->chapterToPlainText($chapter);
58 return $this->download()->directly($chapterText, $chapterSlug . '.txt');
62 * Export a chapter to a simple markdown file.
64 * @throws NotFoundException
66 public function markdown(string $bookSlug, string $chapterSlug)
68 $chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
69 $chapterText = $this->exportFormatter->chapterToMarkdown($chapter);
71 return $this->download()->directly($chapterText, $chapterSlug . '.md');