Skip to main content

Presenterm's presentation exporter

Project description

presenterm-export

A PDF exporter for presenterm.


This is not meant to be used as a standalone tool but instead by running presenterm using the --export-pdf switch.

Installation

This tool requires tmux to be installed. Then simply run:

pip install presenterm-export

Note: make sure that presenterm-export works by running presenterm-export --version before attempting to

generate a PDF file. If you get errors related to weasyprint, follow their installation instructions to ensure you meet all of their dependencies. This has otherwise caused issues in macOS.

How it works

This tool's goal is to capture the output of presenterm and turn it into a PDF file. This section outlines roughly how it works.

Presentation metadata

Before presenterm runs this tool, it will gnerate a JSON blob that contains metadata about the presentation, including:

  • Its path.
  • Where each image is in the original markdown file.
  • The keys that presenterm wants this tool to simulate to capture its contents. This allows this tool to be pretty dumb in terms of capturing: it doesn't even understand slides, it just presses whatever presenterm tells it to.

This metadata is then passed into this tool via stdin.

Capturing

Capturing the output of presenterm is done via tmux by running it, sending keys to it, and performing pane captures.

The output of this stage is a list of panes that contain ANSI escape codes. This means you can print them on a terminal and they'll look good but you can't really turn them into PDF as-is.

Conversion to HTML

The next step is to take the ANSI text and turn it into HTML via ansi2html. This library creates HTML that looks mostly how we want it to but we perform a few transformations so it looks as close to presenterm itself as we can.

Conversion to PDF

Finally, the HTML is converted into PDF by using weasyprint. The result is a PDF that looks exactly as if you had ran presenterm including background colors and images.

Images

Images are tricky and are the reason why this uses HTML as an intermediate step, given they can't be represented with just text so tmux pane captures will ignore them.

Luckily, viuer, the crate presenterm uses to display images, falls back to using text blocks to display images when your terminal emulator doesn't support any of the image protocols (e.g. kitty's). This means if you ran this under tmux you would get an ASCII-based version of your images.

This could be enough but we really want PDF exports to look as close to the real thing as possible. So instead of keeping those ASCII based images, we do the following:

  1. Replace every image with a new image of the same size but made up of a single unique color. This means an image of 300x200px will be replaced with another one of 300x200px but made up of some specific color. The reason for doing this is we can then easily spot these blocks of text in the HTML output, which means we can know exactly where the original image should be in the HTML version of the presentation.
  2. After the transformation to HTML, we do a pass and find every image based on the color we chose for it and replace it with an img tag pointing to its original and using a properly scaled width attribute.
  3. When the PDF generation occurs, the image tags are correctly interpreted and the final PDF output contains every image where it should be.

Presentation size

The size of the page in the generated PDF is the same as the size of the terminal you run presenterm --export-pdf on. That means you should adjust your terminal size before running it so that it fits text however you want it to.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

presenterm_export-0.2.7.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

presenterm_export-0.2.7-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file presenterm_export-0.2.7.tar.gz.

File metadata

  • Download URL: presenterm_export-0.2.7.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for presenterm_export-0.2.7.tar.gz
Algorithm Hash digest
SHA256 f53919e76940d65dcf62cd834e08e2d0b0eb1b9922c6715f7ee3087e120b6351
MD5 749717b4445c07205d8685b7a2fa9c12
BLAKE2b-256 b0b756caa007f7e79e99fa437acf1b8cd4ff19c702166dc81487183590b766a0

See more details on using hashes here.

File details

Details for the file presenterm_export-0.2.7-py3-none-any.whl.

File metadata

File hashes

Hashes for presenterm_export-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f2877c6745c4c53cf0aa5f5a459a9d8edfe288c5be0bf0e2b7d984e57bf8c71e
MD5 91e7809c07e8d3e622cfc643fe6c3b90
BLAKE2b-256 d7a0f0620449e74ac336cffe8c80dc1da784c82360d31e2bafa848ae53e71eb4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page