Skip to content

Instantly share code, notes, and snippets.

@ssddanbrown
Last active January 17, 2024 12:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

Hi, ask how can I leave the first page without the page number and without the header or footers? and the others yes

@ssddanbrown
Copy link
Author

@AlFcl That's not really something that is that'll really be easy to achieve I'm afraid.
You'd have to insert this content at the right point, after the first page's worth of content, but that'd be a tricky thing to target in a scenario like this where content is dynamic.

@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