BookStack icon indicating copy to clipboard operation
BookStack copied to clipboard

[FEATURE] Header/Footer for PDF Export

Open sirup opened this issue 8 years ago • 20 comments

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.

sirup avatar Aug 31 '17 09:08 sirup

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.

Chris-ZA avatar Sep 29 '17 18:09 Chris-ZA

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.

aljawaid avatar Oct 06 '17 08:10 aljawaid

Agree, good request.

p0lp0 avatar Nov 10 '17 03:11 p0lp0

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

Ady-Gould avatar Jan 14 '18 04:01 Ady-Gould

is there any news on this topic?

badsmoke avatar Aug 10 '20 11:08 badsmoke

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?

injektion avatar Sep 10 '20 22:09 injektion

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.

lenusch avatar Sep 11 '20 13:09 lenusch

Hey @ssddanbrown, is there any new about this feature?

joaovitorteixeira avatar Dec 07 '21 15:12 joaovitorteixeira

Any news on this? It would be much appreciated!

emilbasv3 avatar Mar 25 '22 16:03 emilbasv3

Any news on this?

I also support this feature.

Thx.

cervantesl avatar Apr 11 '22 10:04 cervantesl

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.

ssddanbrown avatar Apr 11 '22 11:04 ssddanbrown

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

ssddanbrown avatar Aug 14 '22 14:08 ssddanbrown

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.

ADMDW avatar Mar 25 '23 17:03 ADMDW

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.

ADMDW avatar Mar 26 '23 09:03 ADMDW

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

ADMDW avatar Mar 26 '23 09:03 ADMDW

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

SuperPat45 avatar Jun 28 '23 14:06 SuperPat45

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...

SLongus avatar Sep 22 '23 02:09 SLongus

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.

mitchell-accipio avatar Nov 02 '23 13:11 mitchell-accipio

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)

Koruyo avatar Nov 17 '23 09:11 Koruyo

Any news on this feature? This would be so important =(

SLongus avatar Feb 09 '24 17:02 SLongus