1 <?php namespace BookStack\Http\Controllers\Api;
3 use BookStack\Entities\Models\Page;
4 use BookStack\Entities\Tools\ExportFormatter;
7 class PageExportApiController extends ApiController
9 protected $exportFormatter;
11 public function __construct(ExportFormatter $exportFormatter)
13 $this->exportFormatter = $exportFormatter;
17 * Export a page as a PDF file.
20 public function exportPdf(int $id)
22 $page = Page::visible()->findOrFail($id);
23 $pdfContent = $this->exportFormatter->pageToPdf($page);
24 return $this->downloadResponse($pdfContent, $page->slug . '.pdf');
28 * Export a page as a contained HTML file.
31 public function exportHtml(int $id)
33 $page = Page::visible()->findOrFail($id);
34 $htmlContent = $this->exportFormatter->pageToContainedHtml($page);
35 return $this->downloadResponse($htmlContent, $page->slug . '.html');
39 * Export a page as a plain text file.
41 public function exportPlainText(int $id)
43 $page = Page::visible()->findOrFail($id);
44 $textContent = $this->exportFormatter->pageToPlainText($page);
45 return $this->downloadResponse($textContent, $page->slug . '.txt');