3 namespace BookStack\Http\Controllers;
5 use BookStack\Entities\ExportService;
6 use BookStack\Entities\Repos\EntityRepo;
7 use BookStack\Exceptions\NotFoundException;
10 class BookExportController extends Controller
15 protected $entityRepo;
20 protected $exportService;
23 * BookExportController constructor.
24 * @param EntityRepo $entityRepo
25 * @param ExportService $exportService
27 public function __construct(EntityRepo $entityRepo, ExportService $exportService)
29 $this->entityRepo = $entityRepo;
30 $this->exportService = $exportService;
31 parent::__construct();
35 * Export a book as a PDF file.
36 * @param string $bookSlug
38 * @throws NotFoundException
41 public function pdf(string $bookSlug)
43 $book = $this->entityRepo->getBySlug('book', $bookSlug);
44 $pdfContent = $this->exportService->bookToPdf($book);
45 return $this->downloadResponse($pdfContent, $bookSlug . '.pdf');
49 * Export a book as a contained HTML file.
50 * @param string $bookSlug
52 * @throws NotFoundException
55 public function html(string $bookSlug)
57 $book = $this->entityRepo->getBySlug('book', $bookSlug);
58 $htmlContent = $this->exportService->bookToContainedHtml($book);
59 return $this->downloadResponse($htmlContent, $bookSlug . '.html');
63 * Export a book as a plain text file.
66 * @throws NotFoundException
68 public function plainText(string $bookSlug)
70 $book = $this->entityRepo->getBySlug('book', $bookSlug);
71 $textContent = $this->exportService->bookToPlainText($book);
72 return $this->downloadResponse($textContent, $bookSlug . '.txt');