Skip to content

Instantly share code, notes, and snippets.

@knzm
Last active December 15, 2015 21:29
Show Gist options
  • Save knzm/5326271 to your computer and use it in GitHub Desktop.
Save knzm/5326271 to your computer and use it in GitHub Desktop.
Sphinx で生成した HTML に改ページを埋め込む方法
  1. conf.py に以下の設定を追加する

    html_theme_options = {
        'nosidebar': True,
    }
  2. ドキュメントの先頭に以下の内容を書く

    .. raw:: html
    
        <style type="text/css" media="print">
          div.documentwrapper {
            float: none;
          }
        </style>
    
    .. |pagebreak| raw:: html
    
       <div style="page-break-after:always" />
  3. 改ページしたいところに |pagebreak| を置く

これをブラウザで開いて印刷すれば簡単にPDFができる! (テーマによっては印刷でスタイルが崩れるものもあり)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment