1 <?php namespace BookStack\Http\Controllers\Api;
3 use BookStack\Entities\Models\Chapter;
4 use BookStack\Entities\Tools\ExportFormatter;
7 class ChapterExportApiController extends ApiController
9 protected $exportFormatter;
12 * ChapterExportController constructor.
14 public function __construct(ExportFormatter $exportFormatter)
16 $this->exportFormatter = $exportFormatter;
20 * Export a chapter as a PDF file.
23 public function exportPdf(int $id)
25 $chapter = Chapter::visible()->findOrFail($id);
26 $pdfContent = $this->exportFormatter->chapterToPdf($chapter);
27 return $this->downloadResponse($pdfContent, $chapter->slug . '.pdf');
31 * Export a chapter as a contained HTML file.
34 public function exportHtml(int $id)
36 $chapter = Chapter::visible()->findOrFail($id);
37 $htmlContent = $this->exportFormatter->chapterToContainedHtml($chapter);
38 return $this->downloadResponse($htmlContent, $chapter->slug . '.html');
42 * Export a chapter as a plain text file.
44 public function exportPlainText(int $id)
46 $chapter = Chapter::visible()->findOrFail($id);
47 $textContent = $this->exportFormatter->chapterToPlainText($chapter);
48 return $this->downloadResponse($textContent, $chapter->slug . '.txt');
52 * Export a chapter as a markdown file.
54 public function exportMarkdown(int $id)
56 $chapter = Chapter::visible()->findOrFail($id);
57 $markdown = $this->exportFormatter->chapterToMarkdown($chapter);
58 return $this->downloadResponse($markdown, $chapter->slug . '.md');