1 <?php namespace BookStack\Http\Controllers\Api;
3 use BookStack\Entities\Models\Book;
4 use BookStack\Entities\Tools\ExportFormatter;
5 use BookStack\Entities\Repos\BookRepo;
8 class BookExportApiController extends ApiController
11 protected $exportFormatter;
14 * BookExportController constructor.
16 public function __construct(BookRepo $bookRepo, ExportFormatter $exportFormatter)
18 $this->bookRepo = $bookRepo;
19 $this->exportFormatter = $exportFormatter;
23 * Export a book as a PDF file.
26 public function exportPdf(int $id)
28 $book = Book::visible()->findOrFail($id);
29 $pdfContent = $this->exportFormatter->bookToPdf($book);
30 return $this->downloadResponse($pdfContent, $book->slug . '.pdf');
34 * Export a book as a contained HTML file.
37 public function exportHtml(int $id)
39 $book = Book::visible()->findOrFail($id);
40 $htmlContent = $this->exportFormatter->bookToContainedHtml($book);
41 return $this->downloadResponse($htmlContent, $book->slug . '.html');
45 * Export a book as a plain text file.
47 public function exportPlainText(int $id)
49 $book = Book::visible()->findOrFail($id);
50 $textContent = $this->exportFormatter->bookToPlainText($book);
51 return $this->downloadResponse($textContent, $book->slug . '.txt');