Skip to content

Instantly share code, notes, and snippets.

@ssddanbrown
Last active May 17, 2024 08:49
Show Gist options
  • Save ssddanbrown/bcc9d2e73ec8144a7f4807fd10ddc863 to your computer and use it in GitHub Desktop.
Save ssddanbrown/bcc9d2e73ec8144a7f4807fd10ddc863 to your computer and use it in GitHub Desktop.
BookStack PDF Export header & footer
@if ($format === 'pdf')
<style media="print">
.print-header-footer {
position: fixed;
width: 100%;
}
.print-footer {
position: fixed;
bottom: -40px;
width: 100%;
}
.print-header-footer-inner {
max-width: 840px;
margin: 0 auto;
color: #666;
}
.print-page-number:after {
content: "Page "counter(page);
}
@page {
margin-top: 100px;
margin-bottom: 80px;
}
</style>
<div class="print-header-footer" style="top: -60px;">
<div class="print-header-footer-inner">
<div style="float: left; opacity: 0.6;">
<img height="42" src="data:image/png;base64,{{ base64_encode(file_get_contents(theme_path('logo.png'))) }}">
</div>
<div style="float: right;">
<div class="print-page-number"></div>
</div>
</div>
<div style="clear:both;"></div>
</div>
<div class="print-header-footer" style="bottom: -40px;">
<div class="print-header-footer-inner">
<div style="float: left;">
Copyright 2022
</div>
<div style="float: right;">
<div class="print-page-number"></div>
</div>
</div>
<div style="clear:both;"></div>
</div>
@endif

This gist is to provide the resultant code of a BookStack video guide. The code existed at themes/custom/layouts/parts/export-body-start.blade.php relative to the BookStack installation folder.

This uses the visual theme system so you need to have an theme folder active in your instance. The code assumes you have a logo.png file in the root of your custom theme folder.

@AlFcl
Copy link

AlFcl commented May 26, 2023

@ssddanbrown Now place and customize the dociog that you created but I keep getting the title of the file and I don't need it there.
I need it only on the left side so that it does not occupy the entire title of the document
image

@AlFcl
Copy link

AlFcl commented May 26, 2023

<div class="print-header-footer-inner">
    <div style="float: left;">
    @yield('title')
    </div>
    <div style="float: right; opacity: 0.6;">
    <img height="42" src="data:image/png;base64,{{ base64_encode(file_get_contents(theme_path('logo.png'))) }}">

    </div>
</div>

@AlFcl
Copy link

AlFcl commented May 26, 2023

<div class="print-header-footer" style="bottom: -40px;">
    <div class="print-header-footer-inner">
        <div style="float: left;">
        &copy; {{ date('Y') }} {{ $page->id }}
        </div>
        <div style="float: right;">
            <div class="print-page-number"></div>
        </div>
    </div>
    <div style="clear:both;"></div>
</div>

@AlFcl
Copy link

AlFcl commented May 26, 2023

now just need remove the headers 😄

@Limerick-gh
Copy link

Hi Dan
Thanks for this great tweak for the PDF export layout.

Is it also possible to include the book name to the header?
I tried with
{{ $book->name ?? ''}}
but this remains empty.
It works for page title but not for the book name.
Is there a way to achieve this?

@ssddanbrown
Copy link
Author

@Limerick-gh is this for page exports? If so then {{ $page->book->name ?? '' }} may work. Check it doesn't break book/chapter exports though.

@Limerick-gh
Copy link

Awesome, this works as expected! Thank you so much for your prompt reply! Much appreciated!
And yes this was for page export.
Will pay attention on book/chapter exports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment