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