-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to show same content in every page (same header/footer, by example) when exporting to pdf #806
Comments
I forgot to say I really love your work! I have written a post (in Spanish) in my blog here explaining what is Reveal.js, how to use it and what my fork is for. |
Thanks for sharing! I'm sure that will be useful to someone else when trying to add a fixed header/footer. |
Will this at some point be integrated into reveal.js? |
Complete example: <body>
<style type="text/css">
#header-left {
position: absolute;
top: 0%;
left: 0%;
}
#header-right {
position: absolute;
top: 0%;
right: 0%;
}
#footer-left {
position: absolute;
bottom: 0%;
left: 0%;
}
</style>
<div id="hidden" style="display:none;">
<div id="header">
<div id="header-left">…</div>
<div id="header-right">…</div>
<div id="footer-left">…</div>
</div>
</div>
<div class="reveal">
<div class="slides">
…
</div>
</div>
<script src="reveal.js/lib/js/head.min.js"></script>
<script src="reveal.js/js/reveal.js"></script>
<script>
…
</script>
<script src="jquery/jquery-2.1.3.min.js"></script>
<script type="text/javascript">
var header = $('#header').html();
if ( window.location.search.match( /print-pdf/gi ) ) {
$('.slides > section').prepend(header);
}
else {
$('.slides').prepend(header);
}
</script>
<body> Note that I prepend to Also note that I prepend to Printing is still pretty broken with this code: <section>
The header will appear badly placed, square in the slide.
</section>
<section>
<section>
The header will appear fine here.
</section>
<section>
It will not appear here at all.
</section>
</section> Still, this is a lot better than no headers at all, especially since I only need the horizontal slides in my printout (#1168). |
Hi, I added a link in the wiki to this issue at https://github.com/hakimel/reveal.js/wiki/Example-Presentations |
The methods documented in this issue don't work quite right anymore, so I have found a new method. The main change is adding the elements to the Pseudo-code:
Code: this can be copy-pasted into the end of a reveal.js file (right before the end </body> tag): <style type="text/css">
/* 1. Style header/footer <div> so they are positioned as desired. */
#header-left {
position: absolute;
top: 0%;
left: 0%;
}
#header-right {
position: absolute;
top: 0%;
right: 0%;
}
#footer-left {
position: absolute;
bottom: 0%;
left: 0%;
}
</style>
<!-- 2. Create hidden header/footer <div> -->
<div id="hidden" style="display:none;">
<div id="header">
<div id="header-left">HEADER-LEFT</div>
<div id="header-right">HEADER-RIGHT</div>
<div id="footer-left">FOOTER-LEFT</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript">
// 3. On Reveal.js ready event, copy header/footer <div> into each `.slide-background` <div>
var header = $('#header').html();
if ( window.location.search.match( /print-pdf/gi ) ) {
Reveal.addEventListener( 'ready', function( event ) {
$('.slide-background').append(header);
});
}
else {
$('div.reveal').append(header);
}
</script> |
I am in the middle of doing my first reveal slide. I appreciate @Leftium's work, but the lack of an exportable footer which won't break when reveal updates itself doesn't exactly inspire me with confidence. |
@Leftium, Thank you for sharing! I just used your approach and the result looks just right. 👍 |
Check out my example https://github.com/handsomeyang/reveal.js |
Another example is here |
For others who wind up here and are interested in @Leftium's solution: if you're using Markdown as input with pandoc for conversion, you can put this additional code in a separate file like footer.html and then include it when generating the HTML with |
@sboisen, can you point to an example to such a 'footer.html'. I cannot make it work. |
@antaldaniel Attached is an example i used to include a logo in the footer (renamed to .txt so Git will let me upload it). |
Well, thank you very much...! I read this solution, I was just wondering how to do this when I am rendering from RStudio all the slides.title: "Habits"
|
I don't know about RStudio. In my case, i'm rendering via shell script using a
I'm pretty sure the |
Very nice.. thx a lot.. |
try Kinzi Print Jquery Plugin, it's great and you can print header/footer on every page |
To save effort for anyone who uses Neither (I do understand that the main topic is for PDF and for default layout.) |
Here's one way you could add a header to each PDF page const header = document.createElement('header');
header.textContent = 'My custom header'
Object.assign( header.style, {
position: 'absolute',
top: '0',
left: '0',
width: '100%',
height: '40px',
background: '#fff',
color: '#000'
} );
Reveal.on('pdf-ready', () => {
document.querySelectorAll('.pdf-page').forEach(page => {
page.appendChild(header.cloneNode(true));
});
}) The header uses position absolute and could overlap with content depending on your slide layout. If it does, you can add spacing around the slide using |
Very nice! I tried this approach and it did copy the header to each page while adding |
With Reveal.js there is no way of showing same content in every page (same header/footer, by example) when exporting to pdf. For solving it I have used some JQuery magic in my fork of Reveal.js in the following way:
What I want is that the following HTML be added in every page.
This works in the navigator if we place it before the
<section>
labels, but for showing it in every PDF page we must repeat the HTML fragment in every section.So I used the JQuery code to avoid repeating:
?print-pdf
) insert automatically in every slide, after<section>
<div class="reveal">
Note that titulo is the variable name for title text.
You can see online demo, pdf export and download my fork from here.
The text was updated successfully, but these errors were encountered: