- $cssContent = file_get_contents(public_path('/css/export-styles.css'));
- $pageHtml = view('pages/pdf', ['page' => $page, 'css' => $cssContent])->render();
+ $this->entityRepo->renderPage($page);
+ $html = view('pages/pdf', [
+ 'page' => $page
+ ])->render();
+ return $this->htmlToPdf($html);
+ }
+
+ /**
+ * Convert a chapter to a PDF file.
+ * @param Chapter $chapter
+ * @return mixed|string
+ */
+ public function chapterToPdf(Chapter $chapter)
+ {
+ $pages = $this->entityRepo->getChapterChildren($chapter);
+ $pages->each(function ($page) {
+ $page->html = $this->entityRepo->renderPage($page);
+ });
+ $html = view('chapters/export', [
+ 'chapter' => $chapter,
+ 'pages' => $pages
+ ])->render();
+ return $this->htmlToPdf($html);
+ }
+
+ /**
+ * Convert a book to a PDF file
+ * @param Book $book
+ * @return string
+ */
+ public function bookToPdf(Book $book)
+ {
+ $bookTree = $this->entityRepo->getBookChildren($book, true, true);
+ $html = view('books/export', [
+ 'book' => $book,
+ 'bookChildren' => $bookTree
+ ])->render();
+ return $this->htmlToPdf($html);
+ }
+
+ /**
+ * Convert normal webpage HTML to a PDF.
+ * @param $html
+ * @return string
+ */
+ protected function htmlToPdf($html)
+ {
+ $containedHtml = $this->containHtml($html);