3 namespace BookStack\Exports\Controllers;
5 use BookStack\Entities\Queries\PageQueries;
6 use BookStack\Exports\ExportFormatter;
7 use BookStack\Http\ApiController;
10 class PageExportApiController extends ApiController
12 public function __construct(
13 protected ExportFormatter $exportFormatter,
14 protected PageQueries $queries,
16 $this->middleware('can:content-export');
20 * Export a page as a PDF file.
24 public function exportPdf(int $id)
26 $page = $this->queries->findVisibleByIdOrFail($id);
27 $pdfContent = $this->exportFormatter->pageToPdf($page);
29 return $this->download()->directly($pdfContent, $page->slug . '.pdf');
33 * Export a page as a contained HTML file.
37 public function exportHtml(int $id)
39 $page = $this->queries->findVisibleByIdOrFail($id);
40 $htmlContent = $this->exportFormatter->pageToContainedHtml($page);
42 return $this->download()->directly($htmlContent, $page->slug . '.html');
46 * Export a page as a plain text file.
48 public function exportPlainText(int $id)
50 $page = $this->queries->findVisibleByIdOrFail($id);
51 $textContent = $this->exportFormatter->pageToPlainText($page);
53 return $this->download()->directly($textContent, $page->slug . '.txt');
57 * Export a page as a markdown file.
59 public function exportMarkdown(int $id)
61 $page = $this->queries->findVisibleByIdOrFail($id);
62 $markdown = $this->exportFormatter->pageToMarkdown($page);
64 return $this->download()->directly($markdown, $page->slug . '.md');