3 namespace BookStack\Http\Controllers;
5 use BookStack\Entities\ExportService;
6 use BookStack\Entities\Managers\PageContent;
7 use BookStack\Entities\Repos\PageRepo;
8 use BookStack\Exceptions\NotFoundException;
11 class PageExportController extends Controller
15 protected $exportService;
18 * PageExportController constructor.
19 * @param PageRepo $pageRepo
20 * @param ExportService $exportService
22 public function __construct(PageRepo $pageRepo, ExportService $exportService)
24 $this->pageRepo = $pageRepo;
25 $this->exportService = $exportService;
26 parent::__construct();
30 * Exports a page to a PDF.
31 * https://github.com/barryvdh/laravel-dompdf
32 * @throws NotFoundException
35 public function pdf(string $bookSlug, string $pageSlug)
37 $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
38 $page->html = (new PageContent($page))->render();
39 $pdfContent = $this->exportService->pageToPdf($page);
40 return $this->downloadResponse($pdfContent, $pageSlug . '.pdf');
44 * Export a page to a self-contained HTML file.
45 * @throws NotFoundException
48 public function html(string $bookSlug, string $pageSlug)
50 $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
51 $page->html = (new PageContent($page))->render();
52 $containedHtml = $this->exportService->pageToContainedHtml($page);
53 return $this->downloadResponse($containedHtml, $pageSlug . '.html');
57 * Export a page to a simple plaintext .txt file.
58 * @throws NotFoundException
60 public function plainText(string $bookSlug, string $pageSlug)
62 $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
63 $pageText = $this->exportService->pageToPlainText($page);
64 return $this->downloadResponse($pageText, $pageSlug . '.txt');
68 * Export a page to a simple markdown .md file.
69 * @throws NotFoundException
71 public function markdown(string $bookSlug, string $pageSlug)
73 $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
74 $pageText = $this->exportService->pageToMarkdown($page);
75 return $this->downloadResponse($pageText, $pageSlug . '.md');