Package: presenterm-export
presenterm-exportA PDF exporter forpresenterm.This is not meant to be used as a standalone tool but instead by runningpresentermusing the--export-pdfswitch.InstallationThis tool requirestmuxto be installed. Then simply run:pipinstallpresenterm-exportNote: make sure thatpresenterm-exportworks by runningpresenterm-export --versionbefore attempting togenerate a PDF file. If you get errors related toweasyprint, follow theirinstallation
instructionsto ensure you meet all of their
dependencies. This has otherwise caused issues in macOS.How it worksThis tool's goal is to capture the output ofpresentermand turn it into a PDF file. This section outlines roughly how
it works.Presentation metadataBeforepresentermruns 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 thatpresentermwants 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 whateverpresentermtells it to.This metadata is then passed into this tool via stdin.CapturingCapturing the output ofpresentermis done viatmuxby 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 HTMLThe next step is to take the ANSI text and turn it into HTML viaansi2html.
This library creates HTML that looks mostly how we want it to but we perform a few transformations so it looks as close
topresentermitself as we can.Conversion to PDFFinally, the HTML is converted into PDF by usingweasyprint. The result is a PDF
that looks exactly as if you had ranpresentermincluding background colors and images.ImagesImages are tricky and are the reason why this uses HTML as an intermediate step, given they can't be represented with
just text sotmuxpane captures will ignore them.Luckily,viuer, the cratepresentermuses 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 undertmuxyou would get an ASCII-based version of your images.This could be enough but wereallywant 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 animgtag 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 sizeThe size of the page in the generated PDF is the same as the size of the terminal you runpresenterm --export-pdfon.
That means you should adjust your terminal size before running it so that it fits text however you want it to.