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