3 namespace BookStack\Http\Controllers;
5 use BookStack\Entities\Repos\BookRepo;
6 use BookStack\Entities\Tools\ExportFormatter;
9 class BookExportController extends Controller
12 protected $exportFormatter;
15 * BookExportController constructor.
17 public function __construct(BookRepo $bookRepo, ExportFormatter $exportFormatter)
19 $this->bookRepo = $bookRepo;
20 $this->exportFormatter = $exportFormatter;
24 * Export a book as a PDF file.
28 public function pdf(string $bookSlug)
30 $book = $this->bookRepo->getBySlug($bookSlug);
31 $pdfContent = $this->exportFormatter->bookToPdf($book);
33 return $this->downloadResponse($pdfContent, $bookSlug . '.pdf');
37 * Export a book as a contained HTML file.
41 public function html(string $bookSlug)
43 $book = $this->bookRepo->getBySlug($bookSlug);
44 $htmlContent = $this->exportFormatter->bookToContainedHtml($book);
46 return $this->downloadResponse($htmlContent, $bookSlug . '.html');
50 * Export a book as a plain text file.
52 public function plainText(string $bookSlug)
54 $book = $this->bookRepo->getBySlug($bookSlug);
55 $textContent = $this->exportFormatter->bookToPlainText($book);
57 return $this->downloadResponse($textContent, $bookSlug . '.txt');
61 * Export a book as a markdown file.
63 public function markdown(string $bookSlug)
65 $book = $this->bookRepo->getBySlug($bookSlug);
66 $textContent = $this->exportFormatter->bookToMarkdown($book);
68 return $this->downloadResponse($textContent, $bookSlug . '.md');