]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/BookExportController.php
Merge branch 'master' of git://github.com/albergoniSivaf/BookStack into albergoniSiva...
[bookstack] / app / Http / Controllers / BookExportController.php
1 <?php
2
3 namespace BookStack\Http\Controllers;
4
5 use BookStack\Entities\ExportService;
6 use BookStack\Entities\Repos\BookRepo;
7 use Throwable;
8
9 class BookExportController extends Controller
10 {
11
12     protected $bookRepo;
13     protected $exportService;
14
15     /**
16      * BookExportController constructor.
17      */
18     public function __construct(BookRepo $bookRepo, ExportService $exportService)
19     {
20         $this->bookRepo = $bookRepo;
21         $this->exportService = $exportService;
22         parent::__construct();
23     }
24
25     /**
26      * Export a book as a PDF file.
27      * @throws Throwable
28      */
29     public function pdf(string $bookSlug)
30     {
31         $book = $this->bookRepo->getBySlug($bookSlug);
32         $pdfContent = $this->exportService->bookToPdf($book);
33         return $this->downloadResponse($pdfContent, $bookSlug . '.pdf');
34     }
35
36     /**
37      * Export a book as a contained HTML file.
38      * @throws Throwable
39      */
40     public function html(string $bookSlug)
41     {
42         $book = $this->bookRepo->getBySlug($bookSlug);
43         $htmlContent = $this->exportService->bookToContainedHtml($book);
44         return $this->downloadResponse($htmlContent, $bookSlug . '.html');
45     }
46
47     /**
48      * Export a book as a plain text file.
49      */
50     public function plainText(string $bookSlug)
51     {
52         $book = $this->bookRepo->getBySlug($bookSlug);
53         $textContent = $this->exportService->bookToPlainText($book);
54         return $this->downloadResponse($textContent, $bookSlug . '.txt');
55     }
56 }