create pdfs from markup with python · 2019. 1. 30. · pdf tools. the best thing about pdf? the...
TRANSCRIPT
![Page 1: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/1.jpg)
Create PDFs fromMarkup with Python
Lorna Mitchell
![Page 2: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/2.jpg)
Meet rst2pdf• https://rst2pdf.org• Open source, Python project• Accepts ReStructured Text format, outputs PDF•Useful for: reports, slide decks, ... all sorts
@lornajane
![Page 3: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/3.jpg)
ReStructured Text
@lornajane
![Page 4: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/4.jpg)
ReStructured TextA text-based markup format (like markdown, but better). Use your favourite text editor! Use source control.
@lornajane
![Page 5: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/5.jpg)
A note on source controlSource control is for people who:• don't like losing work• sometimes make mistakes•might want to collaborate with others some day
@lornajane
![Page 6: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/6.jpg)
ReStructured Text ExamplesSlide with bullets: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
![Page 7: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/7.jpg)
ReStructured Text ExamplesCode block:.. code-block:: python
def inbound_sms(): if request.is_json: pprint(request.get_json())
Image:.. image:: images/postman.png:width: 26cm
@lornajane
![Page 8: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/8.jpg)
Portable Document Format
@lornajane
![Page 9: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/9.jpg)
Portable Document FormatPDF is my preferred file format for things that:• should be well presented• need not be edited It is a self-contained, open format, fonts can be embedded, andthere are loads of tools that work with it.
@lornajane
![Page 10: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/10.jpg)
PDF ToolsThe best thing about PDF? The tools!• pdftk for manipulating PDFs (including the surprise later in
this slide deck)• pdfjam for utterly painless handouts• pdfpc for presenting from PDF including speaker notes, timer
etc
@lornajane
![Page 11: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/11.jpg)
Create PDFs fromMarkup with Python
Lorna Mitchell
Meet rst2pdf• https://rst2pdf.org• Open source, Python project• Accepts ReStructured Text format, outputs PDF• Useful for: reports, slide decks, ... all sorts
@lornajane
ReStructured Text
@lornajane
ReStructured TextA text-based markup format (like markdown, but better). Use your favourite text editor! Use source control.
@lornajane
A note on source controlSource control is for people who:• don't like losing work• sometimes make mistakes• might want to collaborate with others some day
@lornajane
ReStructured Text ExamplesSlide with bullets: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
ReStructured Text ExamplesCode block:.. code-block:: python
def inbound_sms(): if request.is_json: pprint(request.get_json())
Image:.. image:: images/postman.png:width: 26cm
@lornajane
Portable Document Format
@lornajane
Portable Document FormatPDF is my preferred file format for things that:• should be well presented• need not be edited It is a self-contained, open format, fonts can be embedded, andthere are loads of tools that work with it.
@lornajane
PDF ToolsThe best thing about PDF? The tools!• pdftk for manipulating PDFs (including the surprise later in
this slide deck)• pdfjam for utterly painless handouts• pdfpc for presenting from PDF including speaker notes,
timer etc
@lornajane
rst2pdf
@lornajane
How to rst2pdfEverything you need is here: https://rst2pdf.org/ pip install rst2pdf
Or on GitHub https://github.com/rst2pdf/rst2pdf
@lornajane
![Page 12: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/12.jpg)
rst2pdf
@lornajane
![Page 13: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/13.jpg)
How to rst2pdfEverything you need is here: https://rst2pdf.org/ pip install rst2pdf
Or on GitHub https://github.com/rst2pdf/rst2pdf
@lornajane
![Page 14: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/14.jpg)
How to rst2pdfEverything you need is here: https://rst2pdf.org/
pip install rst2pdf
Or on GitHub https://github.com/rst2pdf/rst2pdf
@lornajane
![Page 15: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/15.jpg)
How to rst2pdfUse rst2pdf like this:rst2pdf awesomeness.rst
You can supply styles, layouts, output file name but ... this isbasically it
@lornajane
![Page 16: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/16.jpg)
Separate Content and StyleI 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
![Page 17: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/17.jpg)
Code SamplesIt's python, and uses pygments:def inbound_sms(): if request.is_json: pprint(request.get_json()) else: data = dict(request.form) or dict(request.args) pprint(data)
return ('', 204)
https://github.com/nexmo-community/nexmo-python-quickstart
@lornajane
![Page 18: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/18.jpg)
The rst2pdf Project
@lornajane
![Page 19: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/19.jpg)
The rst2pdf ProjectCurrent version: 0.94 Released: 24th January 2019 Previous version: 0.93 Released: 19th December 2012
@lornajane
![Page 20: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/20.jpg)
Project Status• Python 2 only at this moment•Working test suite and decent test coverage• Good documentation, new website
• includes examples, open an issue if you have a question
@lornajane
![Page 21: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/21.jpg)
How do you test a PDF?1. Generate a PDF that is "right"2. Create a hash of that file3. All future tests generate and hash the PDF for this test and
compare it• it's a selection of hashes; different tools make different
outputs
@lornajane
![Page 23: Create PDFs from Markup with Python · 2019. 1. 30. · PDF Tools. The best thing about PDF? The tools! • pdftk. for manipulating PDFs (including the surprise later in this slide](https://reader035.vdocuments.net/reader035/viewer/2022071302/60adbb47a3aca4317b7eab65/html5/thumbnails/23.jpg)
Resourcesrst2pdf
• https://rst2pdf.org• https://github.com/rst2pdf/rst2pdf• https://github.com/ralsina/rst-cheatsheet Me• https://lornajane.net• @lornajane
@lornajane