[FEATURE] Header/Footer for PDF Export
For Feature Requests
For PDF etc. Export it would be nice to set a global Header/Footer to identify where the file is from etc. Maybe also wih Dynamic Fields like Version / Date / Creator.
I would support this request. I was thinking about this the other day when I exported a book.
Our current Microsoft Word document template have this and it helps a lot to have this information on a PDF or printed document.
This would be ideal. Shame we can't currently add the logo or other bits and have the option to remove the 'last edited by' information. Page numbers and a possible optional front cover page would be good too.
Agree, good request.
I also support this feature.
The feature should have items such as:
- page numbers
- chapter title/number
- book title
- draft (when not finalised)
- logo
- date/time
- author/editors/etc
is there any news on this topic?
Hey @ssddanbrown - I've pushed a branch ( https://github.com/injektion/BookStack/tree/exportheaders ) which might help with this... For exports, it'll display a page number in the footer and allow users to create a page to include as a header on every page.
Most of the juice is in partials/export-header-footer.blade.php which is now included in all the /views/[books|chapters|pages]/export.blade.php and checks for a couple .env variables
EXPORT_HEADER_PAGE_SLUG=header
EXPORT_SHOW_PAGE_NUMBERS=true
There's some extra CSS added to partials/export-styles.blade.php which sets up a counter for pages, and if the .env is true will drop it into a footer div
.pagenum:before {
content: counter(page);
}
As for the header, I'm currently letting the user define a page as their header, and then in partials/export-header-footer.blade.php using the slug of that page to import a header....
@if(env("EXPORT_HEADER_PAGE_SLUG"))
<div class="header">
@php
$PAGE = new \BookStack\Entities\Page();
$page = $PAGE::where("slug", "=", env("EXPORT_HEADER_PAGE_SLUG"))->first();
$page->html = (new \BookStack\Entities\Managers\PageContent($page))->render();
@endphp
{!! $page->html !!}
</div>
@endif
It's working fine to allow the user to create their own headers, add some page numbering, and export, but I think there's probably a better flow to how to get the user to define the page to use as their header... Do you have any recommendations on where you'd like to see the header get defined, or do you think this will work for those who want it?
Hey @ssddanbrown - I've pushed a branch ( https://github.com/injektion/BookStack/tree/exportheaders ) which might help with this... For exports, it'll display a page number in the footer and allow users to create a page to include as a header on every page.
can i with this disable Footer informations in PDF? I don't want author etc. inside of Footer.
Hey @ssddanbrown, is there any new about this feature?
Any news on this? It would be much appreciated!
Any news on this?
I also support this feature.
Thx.
There is no news on this upon any additional context within #2311. If there was you'd likely see something here.
The only difference since that PR is that we're now probably more DOMPDF focused rather than WKHTMLtoPDF. Like mentioned in that PR, the visual theme system could likely be used to achieve this, although it may be worth us making template changes to better accommodate this specific feature.
If it helps, I just published a video on using the visual theme system to achieve a footer on PDF exports with the default DomPDF renderer: https://youtu.be/5bZ7zlNEphc
Your video is very helpful - thank you. How can the book title, chapter, and page name be added in addition to the page number? Thanks.
I have found the following after some experimentation:
<div style="float: right; text-align:right; max-width: 530px; font-size:11px;">
@if(isset($page))
{{ $page->book->name }}
<br>
<i>{{ $page->name }}</i>
@else
{{ $book->name }}
@endif
</div>
When I export only one page, both the book title and the page title are displayed, and when I export the entire book, only the book title is displayed. This works for my needs.
This is the whole content of my /var/www/bookstack/themes/myTemplate/layouts/parts/export-body-start.blade.php file:
{{-- This is a placeholder template file provided as a --}}
{{-- convenience to users of the visual theme system. --}}
@if ($format === 'pdf')
<style media="print">
.print-header-footer {
position: fixed;
width: 100%;
}
.print-footer {
position: fixed;
width: 100%;
bottom: -40px;
}
.print-header-footer-inner {
max-width: 840px;
margin: 0px;
color: #666;
}
.print-page-number:after {
content: "Seite " counter(page);
}
@page {
margin-top: 110px;
margin-bottom: 60px;
}
</style>
<!-- Header -->
<div class="print-header-footer" style="top: -90px;">
<div class="print-header-footer-inner">
<div style="float: left; margin:-5px;">
<img height="48px" src="data:image/png;base64,{{ base64_encode(file_get_contents(theme_path('DWLogo.png'))) }}">
</div>
<div style="float: right; text-align:right; max-width: 530px; font-size:11px;">
@if(isset($page))
{{ $page->book->name }}
<br>
{{ $page->name }}
@else
{{ $book->name }}
@endif
</div>
</div>
<div style="clear:both;"></div>
<hr>
</div>
<!-- /Header -->
<!-- Footer -->
<div class="print-header-footer" style="bottom: -40px;">
<hr>
<div class="print-header-footer-inner">
<div style="float: left;">
<!-- ggf. Text unten links -->
</div>
<div style="float: right;">
<div class="print-page-number"></div>
</div>
</div>
<div style="clear:both;"></div>
</div>
<!-- /Footer -->
@endif
To make the function work, add the own template in the /var/www/bookstack/.env file:
APP_THEME=myTemplate
I know a JavaScript library named paged.js https://pagedjs.org/documentation/ which allow complex headers, footers with page numbers, table of content with page number... I use it to generate a full PDF book (1500 pages) in one of my project with node.js + puppeteer module + chromium
This Request is opened since 2017. We try BookStack for as our Documentacion system, but without this function it's not functional for us. The Work Around in the youtube video is very nice, but what are the problems when updating to a new version? That looks like it could be problematic...
We are also using Bookstack as our Documentation system and we use WKHTMLtoPDF for PDF exports thanks to the superior exporting aesthetics; I have seen This Issue That could potentially solve some of the layout issues on DomPDF for us, but branding would be incredibly useful since we want to be able to export policies to provide to customers as part of tender, for example.
In my opinion Export Branding would provide a great enhancement of features that would make Bookstack more usable as a business solution.
I will take solutions in this issue and other relevant issues into consideration but would love to highlight this feature as something my organisation could really use.
For our uses, PDF export would need an index with page numbers, and page headers and or footers with current page/numberofpages e.g. Page 5/200
Sadly i cant find any solution to make bookstack work for us.
While one can hack in simple page numbers in a header or footer (following the youtube video of bookstack about this), it remains sub-optimal for printed documentations not having an index with page numbers and the maximum number of pages to make sure the document is complete/stays/stayed complete. I really like bookstack, i hope some day i can finally make it work for us... (every few years i check sadly it still remains open)
Any news on this feature? This would be so important =(