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 $exportFormatter;
13 * ChapterExportController constructor.
15 public function __construct(ExportFormatter $exportFormatter)
17 $this->exportFormatter = $exportFormatter;
21 * Export a chapter as a PDF file.
24 public function exportPdf(int $id)
26 $chapter = Chapter::visible()->findOrFail($id);
27 $pdfContent = $this->exportFormatter->chapterToPdf($chapter);
28 return $this->downloadResponse($pdfContent, $chapter->slug . '.pdf');
32 * Export a chapter as a contained HTML file.
35 public function exportHtml(int $id)
37 $chapter = Chapter::visible()->findOrFail($id);
38 $htmlContent = $this->exportFormatter->chapterToContainedHtml($chapter);
39 return $this->downloadResponse($htmlContent, $chapter->slug . '.html');
43 * Export a chapter as a plain text file.
45 public function exportPlainText(int $id)
47 $chapter = Chapter::visible()->findOrFail($id);
48 $textContent = $this->exportFormatter->chapterToPlainText($chapter);
49 return $this->downloadResponse($textContent, $chapter->slug . '.txt');