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:
- 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.
- 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. - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file presenterm_export-0.2.5.tar.gz
.
File metadata
- Download URL: presenterm_export-0.2.5.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e87ffd29840495ff46c4d3035a8a8f4f5427c8826df4116ce52d6c4f330f11b |
|
MD5 | be12b784b86b678875d6abd8209dc719 |
|
BLAKE2b-256 | 706cbe8782077087ee903b934e3df90d2c030fdfa9ba192ff5f3b1829b3aad8e |
File details
Details for the file presenterm_export-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: presenterm_export-0.2.5-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2991f40a1a3fac48da21db7fe8ded47e5085c9e38d799b8b8e8a932a329ffbd |
|
MD5 | bfe8bb07ac74d85549ce3a5a96044f7d |
|
BLAKE2b-256 | ebb7cd3dd42c828ee818bf52f8de94ade86bb6cfe1b81edd30ea8d7e3f87158d |