3 namespace BookStack\Entities\Controllers;
5 use BookStack\Entities\Models\Chapter;
6 use BookStack\Entities\Tools\ExportFormatter;
7 use BookStack\Http\ApiController;
10 class ChapterExportApiController extends ApiController
12 protected $exportFormatter;
15 * ChapterExportController constructor.
17 public function __construct(ExportFormatter $exportFormatter)
19 $this->exportFormatter = $exportFormatter;
20 $this->middleware('can:content-export');
24 * Export a chapter as a PDF file.
28 public function exportPdf(int $id)
30 $chapter = Chapter::visible()->findOrFail($id);
31 $pdfContent = $this->exportFormatter->chapterToPdf($chapter);
33 return $this->download()->directly($pdfContent, $chapter->slug . '.pdf');
37 * Export a chapter as a contained HTML file.
41 public function exportHtml(int $id)
43 $chapter = Chapter::visible()->findOrFail($id);
44 $htmlContent = $this->exportFormatter->chapterToContainedHtml($chapter);
46 return $this->download()->directly($htmlContent, $chapter->slug . '.html');
50 * Export a chapter as a plain text file.
52 public function exportPlainText(int $id)
54 $chapter = Chapter::visible()->findOrFail($id);
55 $textContent = $this->exportFormatter->chapterToPlainText($chapter);
57 return $this->download()->directly($textContent, $chapter->slug . '.txt');
61 * Export a chapter as a markdown file.
63 public function exportMarkdown(int $id)
65 $chapter = Chapter::visible()->findOrFail($id);
66 $markdown = $this->exportFormatter->chapterToMarkdown($chapter);
68 return $this->download()->directly($markdown, $chapter->slug . '.md');