LoginSignup
0
5

More than 5 years have passed since last update.

crowi で書いたメモをpdf出力用表示にさせる

Last updated at Posted at 2018-03-27

初投稿。

crowiには、プレゼンテーションモードはあるけど、pdf出力する機能はない。
プレゼンテーションモードにはreveal.jsを利用しているみたいですが、URLの末尾に?print-pdfを付けても印刷用表示にならなかったため、それの対処法。

原因

reveal.jsのreadmeにも書いてありますが、以下のscript文が書かれていないため、印刷用表示にならない。

<script>
    var link = document.createElement( 'link' );
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
    document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>

また、print-pdf指定時の読み込みCSSの場所も変更しておかなければならないため、最終的には以下の行をプレゼンテーションモードのviewページ(/lib/views/page_presentation.html)に追記してあげる必要がある。

<script>
    var link = document.createElement( 'link' );
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.href = window.location.search.match( /print-pdf/gi ) ? '/js/reveal/css/print/pdf.css' : '/js/reveal/css/print/paper.css';
    document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>

自分の環境では、docker-hubにあったcrowiのイメージをそのまま建てただけなので、viコマンドやボリュームをホストとマウントしていなかったため、しぶしぶsedコマンドで対応した。

# cp lib/views/page_presentation.html lib/views/.page_presentation.html.backup
# cat lib/views/page_presentation.html | sed "14 i <script>\nvar link = document.createElement( 'link' );\nlink.rel = 'stylesheet';\nlink.type = 'text/css';\nlink.href = window.location.search.match( /print-pdf/gi ) ? '/js/reveal/css/print/pdf.css' : '/js/reveal/css/print/paper.css';\ndocument.getElementsByTagName( 'head' )[0].appendChild( link );\n</script>\n" > lib/views/page_presentation.html

一応、元のファイルをcpコマンドで.page_presentaition.html.backupで退避しています。

別にこんなまどろっこしい事しなくてもpage_presentation.htmlの<title>の上辺りに書けば多分動きます。

0
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
5