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 BooksExportApiController extends ApiController
12 protected $exportService;
15 * BookExportController constructor.
17 public function __construct(BookRepo $bookRepo, ExportService $exportService)
19 $this->bookRepo = $bookRepo;
20 $this->exportService = $exportService;
21 parent::__construct();
25 * Export a book as a PDF file.
28 public function exportPdf(int $id)
30 $book = Book::visible()->findOrFail($id);
31 $pdfContent = $this->exportService->bookToPdf($book);
32 return $this->downloadResponse($pdfContent, $book->slug . '.pdf');
36 * Export a book as a contained HTML file.
39 public function exportHtml(int $id)
41 $book = Book::visible()->findOrFail($id);
42 $htmlContent = $this->exportService->bookToContainedHtml($book);
43 return $this->downloadResponse($htmlContent, $book->slug . '.html');
47 * Export a book as a plain text file.
49 public function exportPlainText(int $id)
51 $book = Book::visible()->findOrFail($id);
52 $textContent = $this->exportService->bookToPlainText($book);
53 return $this->downloadResponse($textContent, $book->slug . '.txt');