Skip to content

Commit

Permalink
fix issue with deck-wide backgroudns in pdf exports + fix hakimel#2865
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel authored and stefanocampanella committed Mar 1, 2022
1 parent 9ed1380 commit 5eea15f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/reveal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions js/controllers/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ export default class Print {
document.body.style.width = pageWidth + 'px';
document.body.style.height = pageHeight + 'px';

const viewportElement = document.querySelector( '.reveal-viewport' );
let presentationBackground;
if( viewportElement ) {
const viewportStyles = window.getComputedStyle( viewportElement );
if( viewportStyles && viewportStyles.background ) {
presentationBackground = viewportStyles.background;
}
}

// Make sure stretch elements fit on slide
await new Promise( requestAnimationFrame );
this.Reveal.layoutSlideContents( slideWidth, slideHeight );

// Re-run the slide layout so that r-fit-text is applied based on
// the printed slide size
slides.forEach( slide => this.Reveal.slideContent.layout( slide ) );

// Batch scrollHeight access to prevent layout thrashing
await new Promise( requestAnimationFrame );

Expand Down Expand Up @@ -90,13 +95,24 @@ export default class Print {

page.className = 'pdf-page';
page.style.height = ( ( pageHeight + config.pdfPageHeightOffset ) * numberOfPages ) + 'px';

// Copy the presentation-wide background to each individual
// page when printing
if( presentationBackground ) {
page.style.background = presentationBackground;
}

page.appendChild( slide );

// Position the slide inside of the page
slide.style.left = left + 'px';
slide.style.top = top + 'px';
slide.style.width = slideWidth + 'px';

// Re-run the slide layout so that r-fit-text is applied based on
// the printed slide size
this.Reveal.slideContent.layout( slide )

if( slide.slideBackgroundElement ) {
page.insertBefore( slide.slideBackgroundElement, slide );
}
Expand Down

0 comments on commit 5eea15f

Please sign in to comment.