3 namespace BookStack\Http\Controllers;
5 use BookStack\Entities\ExportService;
6 use BookStack\Entities\Repos\BookRepo;
9 class BookExportController extends Controller
13 protected $exportService;
16 * BookExportController constructor.
18 public function __construct(BookRepo $bookRepo, ExportService $exportService)
20 $this->bookRepo = $bookRepo;
21 $this->exportService = $exportService;
22 parent::__construct();
26 * Export a book as a PDF file.
29 public function pdf(string $bookSlug)
31 $book = $this->bookRepo->getBySlug($bookSlug);
32 $pdfContent = $this->exportService->bookToPdf($book);
33 return $this->downloadResponse($pdfContent, $bookSlug . '.pdf');
37 * Export a book as a contained HTML file.
40 public function html(string $bookSlug)
42 $book = $this->bookRepo->getBySlug($bookSlug);
43 $htmlContent = $this->exportService->bookToContainedHtml($book);
44 return $this->downloadResponse($htmlContent, $bookSlug . '.html');
48 * Export a book as a plain text file.
50 public function plainText(string $bookSlug)
52 $book = $this->bookRepo->getBySlug($bookSlug);
53 $textContent = $this->exportService->bookToPlainText($book);
54 return $this->downloadResponse($textContent, $bookSlug . '.txt');