3 namespace BookStack\Http\Controllers\Api;
5 use BookStack\Entities\Models\Page;
6 use BookStack\Entities\Tools\ExportFormatter;
9 class PageExportApiController extends ApiController
11 protected $exportFormatter;
13 public function __construct(ExportFormatter $exportFormatter)
15 $this->exportFormatter = $exportFormatter;
19 * Export a page as a PDF file.
23 public function exportPdf(int $id)
25 $page = Page::visible()->findOrFail($id);
26 $pdfContent = $this->exportFormatter->pageToPdf($page);
28 return $this->downloadResponse($pdfContent, $page->slug . '.pdf');
32 * Export a page as a contained HTML file.
36 public function exportHtml(int $id)
38 $page = Page::visible()->findOrFail($id);
39 $htmlContent = $this->exportFormatter->pageToContainedHtml($page);
41 return $this->downloadResponse($htmlContent, $page->slug . '.html');
45 * Export a page as a plain text file.
47 public function exportPlainText(int $id)
49 $page = Page::visible()->findOrFail($id);
50 $textContent = $this->exportFormatter->pageToPlainText($page);
52 return $this->downloadResponse($textContent, $page->slug . '.txt');
56 * Export a page as a markdown file.
58 public function exportMarkdown(int $id)
60 $page = Page::visible()->findOrFail($id);
61 $markdown = $this->exportFormatter->pageToMarkdown($page);
63 return $this->downloadResponse($markdown, $page->slug . '.md');