3 namespace BookStack\Exports\Controllers;
5 use BookStack\Entities\Queries\BookQueries;
6 use BookStack\Exports\ExportFormatter;
7 use BookStack\Exports\ZipExports\ZipExportBuilder;
8 use BookStack\Http\ApiController;
9 use BookStack\Permissions\Permission;
12 class BookExportApiController extends ApiController
14 public function __construct(
15 protected ExportFormatter $exportFormatter,
16 protected BookQueries $queries,
18 $this->middleware(Permission::ContentExport->middleware());
22 * Export a book as a PDF file.
26 public function exportPdf(int $id)
28 $book = $this->queries->findVisibleByIdOrFail($id);
29 $pdfContent = $this->exportFormatter->bookToPdf($book);
31 return $this->download()->directly($pdfContent, $book->slug . '.pdf');
35 * Export a book as a contained HTML file.
39 public function exportHtml(int $id)
41 $book = $this->queries->findVisibleByIdOrFail($id);
42 $htmlContent = $this->exportFormatter->bookToContainedHtml($book);
44 return $this->download()->directly($htmlContent, $book->slug . '.html');
48 * Export a book as a plain text file.
50 public function exportPlainText(int $id)
52 $book = $this->queries->findVisibleByIdOrFail($id);
53 $textContent = $this->exportFormatter->bookToPlainText($book);
55 return $this->download()->directly($textContent, $book->slug . '.txt');
59 * Export a book as a markdown file.
61 public function exportMarkdown(int $id)
63 $book = $this->queries->findVisibleByIdOrFail($id);
64 $markdown = $this->exportFormatter->bookToMarkdown($book);
66 return $this->download()->directly($markdown, $book->slug . '.md');
70 * Export a book as a contained ZIP export file.
72 public function exportZip(int $id, ZipExportBuilder $builder)
74 $book = $this->queries->findVisibleByIdOrFail($id);
75 $zip = $builder->buildForBook($book);
77 return $this->download()->streamedFileDirectly($zip, $book->slug . '.zip', true);