A4 size with python-pptx

Tips for (automatically) generating PowerPoint reports with python

In python-pptx, it is convenient to handle in inches. So, use A4 size = = 11.69 inch x 8.27 inch.

(python-pptx uses a unit called English Metric Units (EMU) for length. The method to convert this to inches is pptx.util.Inches.)

from pptx import Presentation
from pptx.util import Inches

prs = Presentation()

prs.slide_height=Inches(11.69)
prs.slide_width=Inches(8.27)

prs.save("./hoge.pptx")

With this, I can make it for the time being.

image.png

If you want to paste the title slide layout and a blank slide layout here,

from pptx import Presentation
from pptx.util import Inches

prs = Presentation()

prs.slide_height=Inches(11.69)
prs.slide_width=Inches(8.27)

#Title slide
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)

title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"

#Blank slide
blank_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_slide_layout)

prs.save("./hoge.pptx")

image.png

Will be.

reference

python-pptx 0.6.18 documentation

Recommended Posts

A4 size with python-pptx
Create a PDF file with a random page size
Decorate with a decorator
Center images with python-pptx
Learn librosa with a tutorial 1
Try programming with a shell!
Create a homepage with django
Using a printer with Debian 10
Make a fortune with Python
Create a heatmap with pyqtgraph
Create a directory with python
A little stuck with chainer
Draw a graph with networkx
Easily cProfile with a decorator
Make a fire with kdeplot
NumPy zeros can be defined even with a size of 0
Detect objects of a specific color and size with Python
Building a kubernetes environment with ansible 2
[Python] What is a with statement?
Operate a receipt printer with python
A python graphing manual with Matplotlib.
Play with a turtle with turtle graphics (Part 1)
Draw a graph with Julia + PyQtGraph (2)
Creating a decision tree with scikit-learn
Let's make a GUI with python.
Make a sound with Jupyter notebook
Enumerate files with a specific extension
Creating a Flask server with Docker
Build a deb file with Docker
Solve ABC166 A ~ D with Python
Draw a loose graph with matplotlib
Deploy a Django application with Docker
Let's make a breakout with wxPython
Create a virtual environment with Python!
I made a fortune with Python.
Draw a beautiful circle with numpy
Write a Residual Network with TFLearn
Django Tips-Create a ranking site with Django-
Draw a graph with Julia + PyQtGraph (1)
Building a virtual environment with Python 3
Creating a simple app with flask
Draw a graph with Julia + PyQtGraph (3)
Solve ABC168 A ~ C with Python
Realize a queue with two stacks
Make a recommender system with python
Build a web application with Django
Multi-line size specification reading with python
Generate a Pre-Signed URL with golang
[Python] Generate a password with Slackbot
Solve ABC162 A ~ C with Python
Draw a graph with pandas + XlsxWriter
Make a filter with a django template
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
[Python] Read a csv file with a large data size using a generator
Let's make a graph with python! !!
Let's make a supercomputer with xCAT
Make a model iterator with PySide
Create a poisson stepper with numpy.random
Make a nice graph with plotly
Building a kubernetes environment with ansible 1