3 namespace BookStack\Exports\Controllers;
5 use BookStack\Entities\Queries\BookQueries;
6 use BookStack\Exports\ExportFormatter;
7 use BookStack\Http\Controller;
10 class BookExportController extends Controller
12 public function __construct(
13 protected BookQueries $queries,
14 protected ExportFormatter $exportFormatter,
16 $this->middleware('can:content-export');
20 * Export a book as a PDF file.
24 public function pdf(string $bookSlug)
26 $book = $this->queries->findVisibleBySlugOrFail($bookSlug);
27 $pdfContent = $this->exportFormatter->bookToPdf($book);
29 return $this->download()->directly($pdfContent, $bookSlug . '.pdf');
33 * Export a book as a contained HTML file.
37 public function html(string $bookSlug)
39 $book = $this->queries->findVisibleBySlugOrFail($bookSlug);
40 $htmlContent = $this->exportFormatter->bookToContainedHtml($book);
42 return $this->download()->directly($htmlContent, $bookSlug . '.html');
46 * Export a book as a plain text file.
48 public function plainText(string $bookSlug)
50 $book = $this->queries->findVisibleBySlugOrFail($bookSlug);
51 $textContent = $this->exportFormatter->bookToPlainText($book);
53 return $this->download()->directly($textContent, $bookSlug . '.txt');
57 * Export a book as a markdown file.
59 public function markdown(string $bookSlug)
61 $book = $this->queries->findVisibleBySlugOrFail($bookSlug);
62 $textContent = $this->exportFormatter->bookToMarkdown($book);
64 return $this->download()->directly($textContent, $bookSlug . '.md');