1 <?php namespace BookStack\Http\Controllers\Api;
3 use BookStack\Entities\Chapter;
4 use BookStack\Entities\ExportService;
5 use BookStack\Entities\Repos\BookRepo;
8 class ChapterExportApiController extends ApiController
10 protected $chapterRepo;
11 protected $exportService;
14 * ChapterExportController constructor.
16 public function __construct(BookRepo $chapterRepo, ExportService $exportService)
18 $this->chapterRepo = $chapterRepo;
19 $this->exportService = $exportService;
20 parent::__construct();
24 * Export a chapter as a PDF file.
27 public function exportPdf(int $id)
29 $chapter = Chapter::visible()->findOrFail($id);
30 $pdfContent = $this->exportService->chapterToPdf($chapter);
31 return $this->downloadResponse($pdfContent, $chapter->slug . '.pdf');
35 * Export a chapter as a contained HTML file.
38 public function exportHtml(int $id)
40 $chapter = Chapter::visible()->findOrFail($id);
41 $htmlContent = $this->exportService->chapterToContainedHtml($chapter);
42 return $this->downloadResponse($htmlContent, $chapter->slug . '.html');
46 * Export a chapter as a plain text file.
48 public function exportPlainText(int $id)
50 $chapter = Chapter::visible()->findOrFail($id);
51 $textContent = $this->exportService->chapterToPlainText($chapter);
52 return $this->downloadResponse($textContent, $chapter->slug . '.txt');