Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Create PDFs from markup with rst2pdf

Create PDFs from markup with rst2pdf

Lorna Mitchell

August 18, 2018
Tweet

More Decks by Lorna Mitchell

Other Decks in Technology

Transcript

  1. Create PDFs from
    Markup with rst2pdf
    Lorna Mitchell

    View Slide

  2. Meet rst2pdf
    • http://rst2pdf.github.io
    • Open source, Python project
    • Accepts ReStructured Text format, outputs PDF
    • Useful for: reports, slide decks, ... all sorts
    @lornajane

    View Slide

  3. PDF: Portable Document
    Format
    @lornajane

    View Slide

  4. PDF: Portable Document
    Format
    PDF is my preferred file format for things that:
    • should be well presented
    • need not be edited
    It is an open format, fonts can be embedded, and there are loads
    of tools that work with it.
    @lornajane

    View Slide

  5. ReStructured Text
    @lornajane

    View Slide

  6. ReStructured Text
    A text-based markup format (like markdown, but better).
    Use your favourite text editor!
    Use source control (such as git)
    @lornajane

    View Slide

  7. A note on source control
    Source control is for people who:
    • don't like losing work
    • sometimes make mistakes
    • might want to collaborate with others some day
    @lornajane

    View Slide

  8. ReStructured Text Examples
    Meet ``rst2pdf``
    ==============
    * http://rst2pdf.github.io
    * Open source, Python project
    * Accepts ReStructured Text format, outputs PDF
    * Useful for: reports, slide decks, ... all sorts
    .. raw:: pdf
    PageBreak titlePage
    @lornajane

    View Slide

  9. rst2pdf
    @lornajane

    View Slide

  10. Create a PDF
    Use rst2pdf like this:
    rst2pdf awesomeness.rst
    You can supply styles, layouts, output file name but ... this is
    basically it
    @lornajane

    View Slide

  11. Separate Content and Style
    I love this approach!
    • Style is always consistent throughout document.
    • Styles can be re-used between documents.
    • Content can be re-used between documents.
    • Documents can VERY easily be re-styled (is my contrast OK?).
    • You can grep for content.
    Extra bonus: tool itself is also separate
    @lornajane

    View Slide

  12. Code Samples
    It's python, and uses pygments:
    var iceCream = 'chocolate';
    if (iceCream === 'chocolate') {
    alert('Yay, I love chocolate ice cream!');
    } else {
    alert('Awwww, but chocolate is my favorite...');
    }
    https://developer.mozilla.org/en-US/docs/Learn/Getting_started_wit
    h_the_web/JavaScript_basics
    @lornajane

    View Slide

  13. How to rst2pdf
    @lornajane

    View Slide

  14. How to rst2pdf
    Everything you need is here: https://rst2pdf.org/
    pip install rst2pdf
    Ask questions, open issues, fix the tool ... all on GitHub
    https://github.com/rst2pdf/rst2pdf
    @lornajane

    View Slide