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;
19 $this->middleware('can:content-export');
23 * Export a chapter as a PDF file.
27 public function exportPdf(int $id)
29 $chapter = Chapter::visible()->findOrFail($id);
30 $pdfContent = $this->exportFormatter->chapterToPdf($chapter);
32 return $this->downloadResponse($pdfContent, $chapter->slug . '.pdf');
36 * Export a chapter as a contained HTML file.
40 public function exportHtml(int $id)
42 $chapter = Chapter::visible()->findOrFail($id);
43 $htmlContent = $this->exportFormatter->chapterToContainedHtml($chapter);
45 return $this->downloadResponse($htmlContent, $chapter->slug . '.html');
49 * Export a chapter as a plain text file.
51 public function exportPlainText(int $id)
53 $chapter = Chapter::visible()->findOrFail($id);
54 $textContent = $this->exportFormatter->chapterToPlainText($chapter);
56 return $this->downloadResponse($textContent, $chapter->slug . '.txt');
60 * Export a chapter as a markdown file.
62 public function exportMarkdown(int $id)
64 $chapter = Chapter::visible()->findOrFail($id);
65 $markdown = $this->exportFormatter->chapterToMarkdown($chapter);
67 return $this->downloadResponse($markdown, $chapter->slug . '.md');