javascript reveal.js 打印到 pdf 只打印第一张幻灯片?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23571270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 01:07:28  来源:igfitidea点击:

reveal.js print to pdf only prints the first slide?

javascriptcssgoogle-chromereveal.js

提问by cboettig

I am trying to use the pdf export option of reveal.js as documented in the repo readme.

我正在尝试使用repo readme 中记录的reveal.js 的pdf 导出选项。

I have the following problems:

我有以下问题:

  • I don't see an option for layout (landscape vs portrait) in my chrome print window
  • Printing only ever prints the first slide
  • 我在 chrome 打印窗口中没有看到布局选项(横向与纵向)
  • 打印只打印第一张幻灯片

No idea what I've done wrong or how to troubleshoot it. I'm using the latest version of reveal.js css etc from Github (sha: 131c00689a4c7a18e5c991fc8102347e4594b5d4) on this example file.

不知道我做错了什么或如何解决它。我在这个示例文件中使用了来自 Github 的最新版本的reveal.js css 等(sha:131c00689a4c7a18e5c991fc8102347e4594b5d4)。

I'm using Google-chrome Version 34.0.1847.132 on Ubuntu 14.04

我在 Ubuntu 14.04 上使用 Google-chrome 版本 34.0.1847.132

回答by William Zhang

  1. Remove

    <link rel="stylesheet" media="print" href="reveal.js/css/print/pdf.css" />
    
  2. Add

    <!-- If the query includes 'print-pdf', include the PDF print sheet -->
    <script>
      if( window.location.search.match( /print-pdf/gi ) ) {
        var link = document.createElement( 'link' );
        link.rel = 'stylesheet';
        link.type = 'text/css';
        link.href = 'reveal.js/css/print/pdf.css';
        document.getElementsByTagName( 'head' )[0].appendChild( link );
      }
    </script>
    
  3. Add ?print-pdfto the end of URL, e.g. change .../index.html#to .../index.html?print-pdf#

  1. 消除

    <link rel="stylesheet" media="print" href="reveal.js/css/print/pdf.css" />
    
  2. 添加

    <!-- If the query includes 'print-pdf', include the PDF print sheet -->
    <script>
      if( window.location.search.match( /print-pdf/gi ) ) {
        var link = document.createElement( 'link' );
        link.rel = 'stylesheet';
        link.type = 'text/css';
        link.href = 'reveal.js/css/print/pdf.css';
        document.getElementsByTagName( 'head' )[0].appendChild( link );
      }
    </script>
    
  3. 添加?print-pdf到 URL 的末尾,例如更改.../index.html#.../index.html?print-pdf#

回答by Fred K

I made a presentation using Slides and exported it in HTML, but for me the William Zhanf solution doesn't work at all. I had all the slides overlayed. This is how I solved:

我使用幻灯片制作了一个演示文稿并将其导出为 HTML,但对我来说,William Zhanf 解决方案根本不起作用。我已经覆盖了所有的幻灯片。我是这样解决的:

  1. Download the pdf.cssfrom hereand place it in the same folder with the html file.
  2. Paste before the </body>tag the William Zhanf snippet (with changed path to the css file):
  1. pdf.css这里下载并将其与 html 文件放在同一文件夹中。
  2. </body>标签之前粘贴William Zhanf 片段(更改了 css 文件的路径):
<script>
  if( window.location.search.match( /print-pdf/gi ) ) {
    var link = document.createElement( 'link' );
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.href = 'pdf.css'; // Notice: I changed the path
    document.getElementsByTagName( 'head' )[0].appendChild( link );
  }
</script>
  1. Then follow the same instruction: add ?print-pdfto the end of URL and print as PDF from Chrome.
  1. 然后按照相同的说明:添加?print-pdf到 URL 的末尾并从 Chrome 打印为 PDF。