3 namespace BookStack\Http\Controllers;
5 use BookStack\Entities\Managers\BookContents;
6 use BookStack\Entities\ExportService;
7 use BookStack\Entities\Repos\BookRepo;
10 class BookExportController extends Controller
14 protected $exportService;
17 * BookExportController constructor.
19 public function __construct(BookRepo $bookRepo, ExportService $exportService)
21 $this->bookRepo = $bookRepo;
22 $this->exportService = $exportService;
23 parent::__construct();
27 * Export a book as a PDF file.
30 public function pdf(string $bookSlug)
32 $book = $this->bookRepo->getBySlug($bookSlug);
33 $pdfContent = $this->exportService->bookToPdf($book);
34 return $this->downloadResponse($pdfContent, $bookSlug . '.pdf');
38 * Export a book as a contained HTML file.
41 public function html(string $bookSlug)
43 $book = $this->bookRepo->getBySlug($bookSlug);
44 $htmlContent = $this->exportService->bookToContainedHtml($book);
45 return $this->downloadResponse($htmlContent, $bookSlug . '.html');
49 * Export a book as a plain text file.
51 public function plainText(string $bookSlug)
53 $book = $this->bookRepo->getBySlug($bookSlug);
54 $textContent = $this->exportService->bookToPlainText($book);
55 return $this->downloadResponse($textContent, $bookSlug . '.txt');
59 * Export a book as a markdown file.
61 public function markdown(string $bookSlug)
63 $book = $this->bookRepo->getBySlug($bookSlug);
64 $textContent = $this->exportService->bookToMarkdown($book);
65 return $this->downloadResponse($textContent, $bookSlug . '.md');
69 * Export a book as a zip file, made of markdown files.
71 public function zip(string $bookSlug)
73 $book = $this->bookRepo->getBySlug($bookSlug);
74 $filename = $this->exportService->bookToZip($book);
75 return response()->download($filename);