Skip to content
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

Print to pdf doesn't center in page or print code blocks #563

Closed
braje opened this issue Aug 18, 2013 · 7 comments
Closed

Print to pdf doesn't center in page or print code blocks #563

braje opened this issue Aug 18, 2013 · 7 comments

Comments

@braje
Copy link

braje commented Aug 18, 2013

I am using the latest version of reveal.js (from 8/16 master) and am having a couple of problems with the print to pdf plugin.

The first is that code snippets (inside of a

 block) aren't being included in the pdf.  I am using the highlight plugin (though I am using my own downloaded version so I could include source languages not included with reveal).

The second (much more minor) is that the content of each slide is not centered vertically like it is in the html presentation.

@braje
Copy link
Author

braje commented Aug 18, 2013

Ignore the first issue. It is a problem with my own css...

@hakimel
Copy link
Owner

hakimel commented Aug 18, 2013

I tried but was never able to achieve vertically centered slides in PDF output. Unfortunately no change since then so this limitation will remain.

@hakimel hakimel closed this as completed Aug 18, 2013
@tomByrer
Copy link
Contributor

I would try with a 'print' or 'PDF' specific CSS rule to make a box around the slide, a box inside the full page, then center.

@millermedeiros
Copy link

I got the vertical centering to work by wrapping all slide contents with 2 divs and using flexbox:

function toArray(o) {
  return Array.prototype.slice.call(o);
}

toArray( document.querySelectorAll( '.reveal .slides section' ) ).forEach(function(slide){
  var outerWrapper = document.createElement('div');
  outerWrapper.style.cssText = 'display:flex; align-items:center; height:100%';

  var wrapper = document.createElement('div');
  wrapper.style.width = '100%';
  outerWrapper.appendChild(wrapper);

  toArray( slide.children ).forEach(wrapper.appendChild, wrapper);

  slide.style.height = '100%';
  slide.appendChild(outerWrapper);
});

running this snippet on the dev tools just before exporting the PDF solved the issue for me (chrome 32.0.1652.0 canary).

I'm not submitting a pull request because I don't know what you guys would like to do, if the whole centering logic should be changed to use flexbox in all cases or if it should be just a simple monkey-patch in case isPrintingPDF.

I had the "idea" thanks to solved by flexbox

PS: there is also another issue asking for same feature (#458)

@hakimel
Copy link
Owner

hakimel commented Sep 26, 2013

Thanks @millermedeiros. Hadn't considered flexbox for this.

Judging by http://caniuse.com/flexbox it seems compatible enough to merit a migration from the current JS-based centering for both normal viewing and PDF printing. Will file a new issue to give that a try.

@Ciges
Copy link

Ciges commented Feb 19, 2014

Great! I have just added to my reveal.js presentation and works perfectly

Thanks @millermedeiros!

@Ciges
Copy link

Ciges commented Feb 24, 2014

When using markdown syntax this code does not work and I have not been able to solve it.

I used JQuery and the sections are identified but the content is not inserted :-(

@millermedeiros Could you help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants