presenterm-export


Namepresenterm-export JSON
Version 0.2.5 PyPI version JSON
download
home_pageNone
SummaryPresenterm's presentation exporter
upload_time2024-10-19 20:59:31
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseBSD 2-Clause License Copyright (c) 2023, Matias Fontanini All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords presenterm terminal slideshow
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # presenterm-export

A PDF exporter for [presenterm](https://github.com/mfontanini/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](https://github.com/tmux/tmux/) to be installed. Then simply run:

```shell
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](https://doc.courtbouillon.org/weasyprint/stable/first_steps.html) 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](https://github.com/pycontribs/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](https://github.com/Kozea/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](https://github.com/atanunq/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.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "presenterm-export",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Matias Fontanini <matias.fontanini@gmail.com>",
    "keywords": "presenterm, terminal, slideshow",
    "author": null,
    "author_email": "Matias Fontanini <matias.fontanini@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/70/6c/be8782077087ee903b934e3df90d2c030fdfa9ba192ff5f3b1829b3aad8e/presenterm_export-0.2.5.tar.gz",
    "platform": null,
    "description": "# presenterm-export\n\nA PDF exporter for [presenterm](https://github.com/mfontanini/presenterm).\n\n---\n\n**This is not meant to be used as a standalone tool but instead by running _presenterm_ using the `--export-pdf` \nswitch.**\n\n# Installation\n\nThis tool requires [tmux](https://github.com/tmux/tmux/) to be installed. Then simply run:\n\n```shell\npip install presenterm-export\n```\n\n **Note**: make sure that `presenterm-export` works by running `presenterm-export --version` before attempting to \n> generate a PDF file. If you get errors related to _weasyprint_, follow their [installation \n> instructions](https://doc.courtbouillon.org/weasyprint/stable/first_steps.html) to ensure you meet all of their \n> dependencies. This has otherwise caused issues in macOS.\n\n# How it works\n\nThis tool's goal is to capture the output of _presenterm_ and turn it into a PDF file. This section outlines roughly how \nit works.\n\n## Presentation metadata\n\nBefore _presenterm_ runs this tool, it will gnerate a JSON blob that contains metadata about the presentation, \nincluding:\n* Its path.\n* Where each image is in the original markdown file.\n* The keys that _presenterm_ wants this tool to simulate to capture its contents. This allows this tool to be pretty \n  dumb in terms of capturing: it doesn't even understand slides, it just presses whatever _presenterm_ tells it to.\n\nThis metadata is then passed into this tool via stdin.\n\n## Capturing\n\nCapturing the output of _presenterm_ is done via `tmux` by running it, sending keys to it, and performing pane captures.\n\nThe output of this stage is a list of panes that contain ANSI escape codes. This means you can print them on a terminal \nand they'll look good but you can't really turn them into PDF as-is.\n\n## Conversion to HTML\n\nThe next step is to take the ANSI text and turn it into HTML via [ansi2html](https://github.com/pycontribs/ansi2html). \nThis library creates HTML that looks mostly how we want it to but we perform a few transformations so it looks as close \nto _presenterm_ itself as we can.\n\n## Conversion to PDF\n\nFinally, the HTML is converted into PDF by using [weasyprint](https://github.com/Kozea/WeasyPrint). The result is a PDF \nthat looks exactly as if you had ran _presenterm_ including background colors and images.\n\n# Images\n\nImages are tricky and are the reason why this uses HTML as an intermediate step, given they can't be represented with \njust text so `tmux` pane captures will ignore them.\n\nLuckily, [viuer](https://github.com/atanunq/viuer), the crate _presenterm_ uses to display images, falls back to using \ntext blocks to display images when your terminal emulator doesn't support any of the image protocols (e.g. kitty's). \nThis means if you ran this under `tmux` you would get an ASCII-based version of your images.\n\nThis could be enough but we _really_ want PDF exports to look as close to the real thing as possible. So instead of \nkeeping those ASCII based images, we do the following:\n\n1. Replace every image with a new image of the same size but made up of a single unique color. This means an image of \n   300x200px will be replaced with another one of 300x200px but made up of some specific color. The reason for doing \n   this is we can then easily spot these blocks of text in the HTML output, which means we can know exactly where the \n   original image should be in the HTML version of the presentation.\n2. After the transformation to HTML, we do a pass and find every image based on the color we chose for it and replace it \n   with an `img` tag pointing to its original and using a properly scaled width attribute.\n3. When the PDF generation occurs, the image tags are correctly interpreted and the final PDF output contains every \n   image where it should be.\n\n# Presentation size\n\nThe size of the page in the generated PDF is the same as the size of the terminal you run `presenterm --export-pdf` on. \nThat means you should adjust your terminal size before running it so that it fits text however you want it to.\n\n",
    "bugtrack_url": null,
    "license": "BSD 2-Clause License  Copyright (c) 2023, Matias Fontanini All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  ",
    "summary": "Presenterm's presentation exporter",
    "version": "0.2.5",
    "project_urls": {
        "Bug Reports": "https://github.com/mfontanini/presenterm-export",
        "Homepage": "https://github.com/mfontanini/presenterm-export",
        "Source": "https://github.com/mfontanini/presenterm-export"
    },
    "split_keywords": [
        "presenterm",
        " terminal",
        " slideshow"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ebb7cd3dd42c828ee818bf52f8de94ade86bb6cfe1b81edd30ea8d7e3f87158d",
                "md5": "bfe8bb07ac74d85549ce3a5a96044f7d",
                "sha256": "e2991f40a1a3fac48da21db7fe8ded47e5085c9e38d799b8b8e8a932a329ffbd"
            },
            "downloads": -1,
            "filename": "presenterm_export-0.2.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bfe8bb07ac74d85549ce3a5a96044f7d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 11262,
            "upload_time": "2024-10-19T20:59:29",
            "upload_time_iso_8601": "2024-10-19T20:59:29.586693Z",
            "url": "https://files.pythonhosted.org/packages/eb/b7/cd3dd42c828ee818bf52f8de94ade86bb6cfe1b81edd30ea8d7e3f87158d/presenterm_export-0.2.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "706cbe8782077087ee903b934e3df90d2c030fdfa9ba192ff5f3b1829b3aad8e",
                "md5": "be12b784b86b678875d6abd8209dc719",
                "sha256": "8e87ffd29840495ff46c4d3035a8a8f4f5427c8826df4116ce52d6c4f330f11b"
            },
            "downloads": -1,
            "filename": "presenterm_export-0.2.5.tar.gz",
            "has_sig": false,
            "md5_digest": "be12b784b86b678875d6abd8209dc719",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 11299,
            "upload_time": "2024-10-19T20:59:31",
            "upload_time_iso_8601": "2024-10-19T20:59:31.290235Z",
            "url": "https://files.pythonhosted.org/packages/70/6c/be8782077087ee903b934e3df90d2c030fdfa9ba192ff5f3b1829b3aad8e/presenterm_export-0.2.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-19 20:59:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mfontanini",
    "github_project": "presenterm-export",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "presenterm-export"
}
        
Elapsed time: 0.56377s