3 namespace BookStack\Http\Controllers;
5 use BookStack\Entities\Tools\ExportFormatter;
6 use BookStack\Entities\Repos\BookRepo;
9 class BookExportController extends Controller
13 protected $exportFormatter;
16 * BookExportController constructor.
18 public function __construct(BookRepo $bookRepo, ExportFormatter $exportFormatter)
20 $this->bookRepo = $bookRepo;
21 $this->exportFormatter = $exportFormatter;
25 * 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);
32 return $this->downloadResponse($pdfContent, $bookSlug . '.pdf');
36 * Export a book as a contained HTML file.
39 public function html(string $bookSlug)
41 $book = $this->bookRepo->getBySlug($bookSlug);
42 $htmlContent = $this->exportFormatter->bookToContainedHtml($book);
43 return $this->downloadResponse($htmlContent, $bookSlug . '.html');
47 * Export a book as a plain text file.
49 public function plainText(string $bookSlug)
51 $book = $this->bookRepo->getBySlug($bookSlug);
52 $textContent = $this->exportFormatter->bookToPlainText($book);
53 return $this->downloadResponse($textContent, $bookSlug . '.txt');
57 * Export a book as a markdown file.
59 public function markdown(string $bookSlug)
61 $book = $this->bookRepo->getBySlug($bookSlug);
62 $textContent = $this->exportFormatter->bookToMarkdown($book);
63 return $this->downloadResponse($textContent, $bookSlug . '.md');