3 namespace BookStack\Http\Controllers\Api;
5 use BookStack\Entities\Models\Book;
6 use BookStack\Entities\Tools\ExportFormatter;
9 class BookExportApiController extends ApiController
11 protected $exportFormatter;
13 public function __construct(ExportFormatter $exportFormatter)
15 $this->exportFormatter = $exportFormatter;
16 $this->middleware('can:content-export');
20 * Export a book as a PDF file.
24 public function exportPdf(int $id)
26 $book = Book::visible()->findOrFail($id);
27 $pdfContent = $this->exportFormatter->bookToPdf($book);
29 return $this->download()->directly($pdfContent, $book->slug . '.pdf');
33 * Export a book as a contained HTML file.
37 public function exportHtml(int $id)
39 $book = Book::visible()->findOrFail($id);
40 $htmlContent = $this->exportFormatter->bookToContainedHtml($book);
42 return $this->download()->directly($htmlContent, $book->slug . '.html');
46 * Export a book as a plain text file.
48 public function exportPlainText(int $id)
50 $book = Book::visible()->findOrFail($id);
51 $textContent = $this->exportFormatter->bookToPlainText($book);
53 return $this->download()->directly($textContent, $book->slug . '.txt');
57 * Export a book as a markdown file.
59 public function exportMarkdown(int $id)
61 $book = Book::visible()->findOrFail($id);
62 $markdown = $this->exportFormatter->bookToMarkdown($book);
64 return $this->download()->directly($markdown, $book->slug . '.md');