3 namespace BookStack\Entities\Controllers;
5 use BookStack\Entities\Queries\ChapterQueries;
6 use BookStack\Entities\Tools\ExportFormatter;
7 use BookStack\Http\ApiController;
10 class ChapterExportApiController extends ApiController
12 public function __construct(
13 protected ExportFormatter $exportFormatter,
14 protected ChapterQueries $queries,
16 $this->middleware('can:content-export');
20 * Export a chapter as a PDF file.
24 public function exportPdf(int $id)
26 $chapter = $this->queries->findVisibleByIdOrFail($id);
27 $pdfContent = $this->exportFormatter->chapterToPdf($chapter);
29 return $this->download()->directly($pdfContent, $chapter->slug . '.pdf');
33 * Export a chapter as a contained HTML file.
37 public function exportHtml(int $id)
39 $chapter = $this->queries->findVisibleByIdOrFail($id);
40 $htmlContent = $this->exportFormatter->chapterToContainedHtml($chapter);
42 return $this->download()->directly($htmlContent, $chapter->slug . '.html');
46 * Export a chapter as a plain text file.
48 public function exportPlainText(int $id)
50 $chapter = $this->queries->findVisibleByIdOrFail($id);
51 $textContent = $this->exportFormatter->chapterToPlainText($chapter);
53 return $this->download()->directly($textContent, $chapter->slug . '.txt');
57 * Export a chapter as a markdown file.
59 public function exportMarkdown(int $id)
61 $chapter = $this->queries->findVisibleByIdOrFail($id);
62 $markdown = $this->exportFormatter->chapterToMarkdown($chapter);
64 return $this->download()->directly($markdown, $chapter->slug . '.md');