Skip to content

Commit 102454a

Browse files
authored
Merge pull request #762 from ayoub-berdeddouch/main
PPT to PDF Converter Python Windows/Linux
2 parents 63812d6 + 6cd4ca7 commit 102454a

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

ppt2pdf/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Package/Script Name: ppt2pdf
2+
3+
* PPT to PDF Converter with Python
4+
* For Windows users & Linux ones.
5+
*
6+
7+
8+
# Setup instructions
9+
## For Windows
10+
11+
## Note that `comtypes` is only available for Windows.
12+
13+
* Function `PPTtoPDF()`
14+
* Fucntion `PPTtoPDFNote()`
15+
16+
**How to use :**
17+
18+
```console
19+
PPTtoPDF('InputFile.pptx', 'OutputFile.pdf')
20+
```
21+
---
22+
```console
23+
PPTtoPDFNote('InputFile.pptx', 'Output_with_Note.pdf')
24+
```
25+
26+
27+
## For Linux
28+
29+
* Install requirements
30+
31+
```console
32+
sudo apt install unoconv
33+
pip install tqdm
34+
pip install glob
35+
```
36+
37+
# Output
38+
39+
* The `PDF/PDFNote` file
40+
41+
42+
# Author:
43+
44+
## [Ayoub Berdeddouch](https://github.com/ayoub-berdeddouch)

ppt2pdf/ppt2pdf_linux.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# import libraries
2+
import glob
3+
import tqdm
4+
import os
5+
6+
PATH = "INPUT FOLDER"
7+
# extension
8+
et = "pptx" # or ppt
9+
files = [f for f in glob.glob(PATH + "/**/*.{}".format(et), recursive=True)]
10+
for f in tqdm.tqdm(files):
11+
command = "unoconv -f pdf \"{}\"".format(f)
12+
os.system(command)

ppt2pdf/ppt2pdf_win.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Note that comtypes is only available for Windows.
2+
from comtypes.client import CreateObject, Constants
3+
4+
5+
# Function PPTtoPDF
6+
def PPTtoPDF(inputFileName, outputFileName, formatType=2):
7+
powerpoint = CreateObject('Powerpoint.Application')
8+
constants = Constants(powerpoint)
9+
powerpoint.Visible = 1
10+
11+
if outputFileName[-3:] != 'pdf':
12+
outputFileName = outputFileName + ".pdf"
13+
deck = powerpoint.Presentations.Open(inputFileName)
14+
deck.SaveAs(outputFileName, constants.PpSaveAsPDF)
15+
deck.Close()
16+
powerpoint.Quit()
17+
18+
19+
# Function PPTtoPDFNote
20+
def PPTtoPDFNote(inputFileName, outputFileName, formatType=32):
21+
powerpoint = CreateObject('Powerpoint.Application')
22+
constants = Constants(powerpoint)
23+
powerpoint.Visible = 1
24+
25+
if outputFileName[-3:] != 'pdf':
26+
outputFileName = outputFileName + ".pdf"
27+
deck = powerpoint.Presentations.Open(inputFileName)
28+
deck.ExportAsFixedFormat(
29+
outputFileName,
30+
constants.ppFixedFormatTypePDF,
31+
constants.ppFixedFormatIntentPrint,
32+
False, # No frame
33+
constants.ppPrintHandoutHorizontalFirst,
34+
constants.ppPrintOutputNotesPages,
35+
constants.ppPrintAll
36+
)
37+
deck.Close()
38+
powerpoint.Quit()

0 commit comments

Comments
 (0)