3 namespace BookStack\Http\Controllers\Api;
5 use BookStack\Entities\Models\Chapter;
6 use BookStack\Entities\Tools\ExportFormatter;
9 class ChapterExportApiController extends ApiController
11 protected $exportFormatter;
14 * ChapterExportController constructor.
16 public function __construct(ExportFormatter $exportFormatter)
18 $this->exportFormatter = $exportFormatter;
22 * Export a chapter as a PDF file.
26 public function exportPdf(int $id)
28 $chapter = Chapter::visible()->findOrFail($id);
29 $pdfContent = $this->exportFormatter->chapterToPdf($chapter);
31 return $this->downloadResponse($pdfContent, $chapter->slug . '.pdf');
35 * Export a chapter as a contained HTML file.
39 public function exportHtml(int $id)
41 $chapter = Chapter::visible()->findOrFail($id);
42 $htmlContent = $this->exportFormatter->chapterToContainedHtml($chapter);
44 return $this->downloadResponse($htmlContent, $chapter->slug . '.html');
48 * Export a chapter as a plain text file.
50 public function exportPlainText(int $id)
52 $chapter = Chapter::visible()->findOrFail($id);
53 $textContent = $this->exportFormatter->chapterToPlainText($chapter);
55 return $this->downloadResponse($textContent, $chapter->slug . '.txt');
59 * Export a chapter as a markdown file.
61 public function exportMarkdown(int $id)
63 $chapter = Chapter::visible()->findOrFail($id);
64 $markdown = $this->exportFormatter->chapterToMarkdown($chapter);
66 return $this->downloadResponse($markdown, $chapter->slug . '.md');