3 namespace BookStack\Entities\Controllers;
5 use BookStack\Entities\Repos\BookRepo;
6 use BookStack\Entities\Tools\ExportFormatter;
7 use BookStack\Http\Controllers\Controller;
10 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;
22 $this->middleware('can:content-export');
26 * Export a book as a PDF file.
30 public function pdf(string $bookSlug)
32 $book = $this->bookRepo->getBySlug($bookSlug);
33 $pdfContent = $this->exportFormatter->bookToPdf($book);
35 return $this->download()->directly($pdfContent, $bookSlug . '.pdf');
39 * Export a book as a contained HTML file.
43 public function html(string $bookSlug)
45 $book = $this->bookRepo->getBySlug($bookSlug);
46 $htmlContent = $this->exportFormatter->bookToContainedHtml($book);
48 return $this->download()->directly($htmlContent, $bookSlug . '.html');
52 * Export a book as a plain text file.
54 public function plainText(string $bookSlug)
56 $book = $this->bookRepo->getBySlug($bookSlug);
57 $textContent = $this->exportFormatter->bookToPlainText($book);
59 return $this->download()->directly($textContent, $bookSlug . '.txt');
63 * Export a book as a markdown file.
65 public function markdown(string $bookSlug)
67 $book = $this->bookRepo->getBySlug($bookSlug);
68 $textContent = $this->exportFormatter->bookToMarkdown($book);
70 return $this->download()->directly($textContent, $bookSlug . '.md');