+
+ /**
+ * Export a book as a PDF file.
+ * @param string $bookSlug
+ * @return mixed
+ */
+ public function exportPdf($bookSlug)
+ {
+ $book = $this->entityRepo->getBySlug('book', $bookSlug);
+ $pdfContent = $this->exportService->bookToPdf($book);
+ return $this->downloadResponse($pdfContent, $bookSlug . '.pdf');
+ }
+
+ /**
+ * Export a book as a contained HTML file.
+ * @param string $bookSlug
+ * @return mixed
+ */
+ public function exportHtml($bookSlug)
+ {
+ $book = $this->entityRepo->getBySlug('book', $bookSlug);
+ $htmlContent = $this->exportService->bookToContainedHtml($book);
+ return $this->downloadResponse($htmlContent, $bookSlug . '.html');
+ }
+
+ /**
+ * Export a book as a plain text file.
+ * @param $bookSlug
+ * @return mixed
+ */
+ public function exportPlainText($bookSlug)
+ {
+ $book = $this->entityRepo->getBySlug('book', $bookSlug);
+ $textContent = $this->exportService->bookToPlainText($book);
+ return $this->downloadResponse($textContent, $bookSlug . '.txt');
+ }
+
+ /**
+ * Common actions to run on book update.
+ * Handles updating the cover image.
+ * @param Book $book
+ * @param Request $request
+ * @throws \BookStack\Exceptions\ImageUploadException
+ */
+ protected function bookUpdateActions(Book $book, Request $request)
+ {
+ // Update the cover image if in request
+ if ($request->has('image')) {
+ $this->imageRepo->destroyImage($book->cover);
+ $newImage = $request->file('image');
+ $image = $this->imageRepo->saveNew($newImage, 'cover_book', $book->id, 512, 512, true);
+ $book->image_id = $image->id;
+ $book->save();
+ }
+
+ if ($request->has('image_reset')) {
+ $this->imageRepo->destroyImage($book->cover);
+ $book->image_id = 0;
+ $book->save();
+ }
+ }