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;
11 class PageExportApiController extends ApiController
13 public function __construct(
14 protected ExportFormatter $exportFormatter,
15 protected PageQueries $queries,
17 $this->middleware('can:content-export');
21 * Export a page as a PDF file.
25 public function exportPdf(int $id)
27 $page = $this->queries->findVisibleByIdOrFail($id);
28 $pdfContent = $this->exportFormatter->pageToPdf($page);
30 return $this->download()->directly($pdfContent, $page->slug . '.pdf');
34 * Export a page as a contained HTML file.
38 public function exportHtml(int $id)
40 $page = $this->queries->findVisibleByIdOrFail($id);
41 $htmlContent = $this->exportFormatter->pageToContainedHtml($page);
43 return $this->download()->directly($htmlContent, $page->slug . '.html');
47 * Export a page as a plain text file.
49 public function exportPlainText(int $id)
51 $page = $this->queries->findVisibleByIdOrFail($id);
52 $textContent = $this->exportFormatter->pageToPlainText($page);
54 return $this->download()->directly($textContent, $page->slug . '.txt');
58 * Export a page as a markdown file.
60 public function exportMarkdown(int $id)
62 $page = $this->queries->findVisibleByIdOrFail($id);
63 $markdown = $this->exportFormatter->pageToMarkdown($page);
65 return $this->download()->directly($markdown, $page->slug . '.md');
70 public function exportZip(int $id, ZipExportBuilder $builder)
72 $page = $this->queries->findVisibleByIdOrFail($id);
73 $pageSlug = $page->slug;
74 $zip = $builder->buildForPage($page);
76 return $this->download()->streamedFileDirectly($zip, $pageSlug . '.zip', filesize($zip), true);