Render ppt like a jupyter notebook
Project description
PPTX Renderer
This package let's you run your powerpoint presentations like a jupyter-notebook. You can insert placeholders in the ppt and also write python code in the ppt's notes and use either a python function or an equivalent commandline tool to convert it into an output rendered presentation.
Installation
pip install pptx-renderer
Usage
Below is a simple example.
from pptx_renderer import PPTXRenderer
p = PPTXRenderer("template.pptx")
someval = "hello"
def mymethod(abc):
return f"{abc} " * 5
myimage = r"is_it_worth_the_time.png"
mytable = [["a", "b", "c", "d", "e"]] * 10
p.render(
"output.pptx",
{
"someval": someval, "mymethod": mymethod, "myimage": myimage,
"mytable": mytable,
}
)
This will convert this
to this.
You can define some functions within the ppt itself by writing python code in the notes section of slides. And the variables and functions in this code can be used in the main ppt.
For example: write the following in one of the slide's notes.
```python def myfunc(input): return input * 42 ```
Now you can, for example, add the placeholder {{{myfunc(42)}}}
in your slides.
If the template ppt is a self contained python script ie: if it does not require variable values and function definition to be passed from outside, you can generate the output ppt directly from the commandline using the following command.
pptx-renderer input_template.pptx output_file.pptx
Placeholders
You can have placeholders for text, image or a table. Placeholders can be added
inside text boxes and shapes. All placeholders should be enclosed within a pair
of triple braces ({{{
and }}}
).
Text
Any placeholder which can be evaluated into a string can act as a text placeholder.
For example: {{{"hello " * 10/2}}}
or {{{abs(-2)}}}
Image
if you have added :image()
as a suffix to the python statement, the renderer will
try to convert the value of python statement to a file location and insert an
image from that file location.
For example: {{{"c:\temp\myimage.png":image()}}}
Table
Tables are similar to images, but only that instead of a string, the python
statement should evaluate to a list of lists. Then you can add :table()
as a
suffix and it will be convert to a table inside the ppt.
For example: {{{[["col1", "col2", "col3"],[1, 2, 3]]:table()}}}
will render to
col1 | col2 | col3 |
---|---|---|
1 | 2 | 3 |
Code in slide notes
You can write regular python code in the slide notes but enclosed between
```python
and ```
.
For example: Create a new pptx and write the following in the first slide's notes
```python
import numpy as np
myarr = np.array([[1, 2], [3, 4]])
```
And in the slide, create a rectangluar shape and add the text {{{myarr:table()}}}
and a text box with the text The determinant of the array is {{{np.linalg.det(myarr)}}}
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 pptx_renderer-0.4.1.tar.gz
.
File metadata
- Download URL: pptx_renderer-0.4.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 289cffe1f160b1d80eeed99fe6dca8794dd433b6bc672139356c282b4cee08b9 |
|
MD5 | 562293fbf6f429f091af56b931f05042 |
|
BLAKE2b-256 | 66ba3e2db1ed41e371f8892cc2db30ce183d1e506e02b74e4f7472d0ce4bc2f3 |
File details
Details for the file pptx_renderer-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: pptx_renderer-0.4.1-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cd5ee91974da03494746ff118359789b36d360d7f3c1f5b9889af327df4183a |
|
MD5 | 4183e48fd17732d85dd354f926e2c4d9 |
|
BLAKE2b-256 | 94550c5717083b7c8e76dbb373d4ca95ee80b0de361c1e08377aaa01b4a1b7d4 |