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;
21 $this->middleware('can:content-export');
25 * Export a book as a PDF file.
29 public function pdf(string $bookSlug)
31 $book = $this->bookRepo->getBySlug($bookSlug);
32 $pdfContent = $this->exportFormatter->bookToPdf($book);
34 return $this->download()->directly($pdfContent, $bookSlug . '.pdf');
38 * Export a book as a contained HTML file.
42 public function html(string $bookSlug)
44 $book = $this->bookRepo->getBySlug($bookSlug);
45 $htmlContent = $this->exportFormatter->bookToContainedHtml($book);
47 return $this->download()->directly($htmlContent, $bookSlug . '.html');
51 * Export a book as a plain text file.
53 public function plainText(string $bookSlug)
55 $book = $this->bookRepo->getBySlug($bookSlug);
56 $textContent = $this->exportFormatter->bookToPlainText($book);
58 return $this->download()->directly($textContent, $bookSlug . '.txt');
62 * Export a book as a markdown file.
64 public function markdown(string $bookSlug)
66 $book = $this->bookRepo->getBySlug($bookSlug);
67 $textContent = $this->exportFormatter->bookToMarkdown($book);
69 return $this->download()->directly($textContent, $bookSlug . '.md');