]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/Api/PageExportApiController.php
Added force option for update-url command
[bookstack] / app / Http / Controllers / Api / PageExportApiController.php
1 <?php
2
3 namespace BookStack\Http\Controllers\Api;
4
5 use BookStack\Entities\Models\Page;
6 use BookStack\Entities\Tools\ExportFormatter;
7 use Throwable;
8
9 class PageExportApiController extends ApiController
10 {
11     protected $exportFormatter;
12
13     public function __construct(ExportFormatter $exportFormatter)
14     {
15         $this->exportFormatter = $exportFormatter;
16         $this->middleware('can:content-export');
17     }
18
19     /**
20      * Export a page as a PDF file.
21      *
22      * @throws Throwable
23      */
24     public function exportPdf(int $id)
25     {
26         $page = Page::visible()->findOrFail($id);
27         $pdfContent = $this->exportFormatter->pageToPdf($page);
28
29         return $this->download()->directly($pdfContent, $page->slug . '.pdf');
30     }
31
32     /**
33      * Export a page as a contained HTML file.
34      *
35      * @throws Throwable
36      */
37     public function exportHtml(int $id)
38     {
39         $page = Page::visible()->findOrFail($id);
40         $htmlContent = $this->exportFormatter->pageToContainedHtml($page);
41
42         return $this->download()->directly($htmlContent, $page->slug . '.html');
43     }
44
45     /**
46      * Export a page as a plain text file.
47      */
48     public function exportPlainText(int $id)
49     {
50         $page = Page::visible()->findOrFail($id);
51         $textContent = $this->exportFormatter->pageToPlainText($page);
52
53         return $this->download()->directly($textContent, $page->slug . '.txt');
54     }
55
56     /**
57      * Export a page as a markdown file.
58      */
59     public function exportMarkdown(int $id)
60     {
61         $page = Page::visible()->findOrFail($id);
62         $markdown = $this->exportFormatter->pageToMarkdown($page);
63
64         return $this->download()->directly($markdown, $page->slug . '.md');
65     }
66 }