1 <?php namespace BookStack\Http\Controllers\Api;
3 use BookStack\Entities\Models\Chapter;
4 use BookStack\Entities\Tools\ExportFormatter;
5 use BookStack\Entities\Repos\BookRepo;
8 class ChapterExportApiController extends ApiController
10 protected $chapterRepo;
11 protected $exportFormatter;
14 * ChapterExportController constructor.
16 public function __construct(BookRepo $chapterRepo, ExportFormatter $exportFormatter)
18 $this->chapterRepo = $chapterRepo;
19 $this->exportFormatter = $exportFormatter;
23 * 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);
30 return $this->downloadResponse($pdfContent, $chapter->slug . '.pdf');
34 * Export a chapter as a contained HTML file.
37 public function exportHtml(int $id)
39 $chapter = Chapter::visible()->findOrFail($id);
40 $htmlContent = $this->exportFormatter->chapterToContainedHtml($chapter);
41 return $this->downloadResponse($htmlContent, $chapter->slug . '.html');
45 * Export a chapter as a plain text file.
47 public function exportPlainText(int $id)
49 $chapter = Chapter::visible()->findOrFail($id);
50 $textContent = $this->exportFormatter->chapterToPlainText($chapter);
51 return $this->downloadResponse($textContent, $chapter->slug . '.txt');