Convert PDF files to PowerPoint presentations
Project description
pdf2ppt-converter
A simple and easy-to-use Python library that converts PDF files to PowerPoint presentations by converting each page to an image.
Features
- One-click conversion - Convert PDF to PPT with a single line of code
- Auto-fit dimensions - Automatically detects PDF aspect ratio and adjusts PPT size
- High quality - Supports custom DPI up to 600
- Batch processing - Convert multiple PDF files at once
- Smart cropping - Optional automatic white space cropping
- Cross-platform - Works on Windows, macOS, and Linux
Installation
pip install pdf2ppt-converter
Additional Requirements
Windows users need to install poppler:
- Download from: https://github.com/oschwartz10612/poppler-windows/releases
- Extract to a directory (e.g.,
C:\poppler) - Add
C:\poppler\Library\binto your system PATH
macOS users:
brew install poppler
Linux users:
# Ubuntu/Debian
sudo apt-get install poppler-utils
# Fedora/CentOS
sudo yum install poppler-utils
Quick Start
Basic Usage
from pdf2ppt import pdf_to_ppt
# Simple conversion
pdf_to_ppt("presentation.pdf")
# Output: presentation.pptx
# Custom output and resolution
pdf_to_ppt("presentation.pdf", "output.pptx", dpi=300)
Advanced Usage
from pdf2ppt import PDF2PPT
# Create converter
converter = PDF2PPT("presentation.pdf", dpi=300, crop_whitespace=True)
# Convert PDF to images
images = converter.convert_pdf_to_images()
print(f"Converted {len(images)} pages")
# Create PPT (auto-fit aspect ratio)
converter.create_ppt()
# Or manually specify 16:9 ratio
converter.create_ppt(width=10, height=5.625)
Batch Conversion
from pdf2ppt import batch_convert
# Convert multiple PDFs
batch_convert(["doc1.pdf", "doc2.pdf", "doc3.pdf"], dpi=300)
Command Line
After installation, you can use it directly from command line:
# Basic usage
pdf2ppt presentation.pdf
# Specify output file
pdf2ppt presentation.pdf output.pptx
# Specify resolution
pdf2ppt presentation.pdf output.pptx 200
API Reference
pdf_to_ppt(pdf_path, output_ppt=None, dpi=300, crop_whitespace=True)
Convenience function to convert PDF to PPT in one step.
Parameters:
pdf_path(str): Path to input PDF fileoutput_ppt(str, optional): Output PPT path, defaults to PDF namedpi(int, optional): Image resolution, default 300crop_whitespace(bool, optional): Whether to crop white borders, default True
Returns: str - Path to output PPT file
PDF2PPT Class
Initialization
converter = PDF2PPT(
pdf_path="presentation.pdf",
output_ppt="output.pptx", # optional
dpi=300, # optional
crop_whitespace=True # optional
)
Methods
convert_pdf_to_images() -> list
- Converts PDF to list of images
- Returns: List of PIL Image objects
create_ppt(width=10, height=None, auto_fit=True) -> str
- Creates PPT and inserts images
- Parameters:
width(float): PPT width in inchesheight(float): PPT height in inches, auto-calculated if Noneauto_fit(bool): Whether to auto-fit aspect ratio
- Returns: Path to output PPT file
convert() -> str
- One-step conversion: PDF ��� PPT
- Returns: Path to output PPT file
batch_convert(pdf_files, dpi=300, crop_whitespace=True)
Convert multiple PDF files in batch.
Parameters:
pdf_files(list): List of PDF file pathsdpi(int, optional): Image resolution, default 300crop_whitespace(bool, optional): Whether to crop white borders, default True
Configuration Guide
DPI Settings
| DPI | Use Case | File Size | Quality |
|---|---|---|---|
| 150 | Preview/Draft | Small | Fair |
| 200 | Daily use | Medium | Good |
| 300 | Formal presentation (Recommended) | Large | High |
| 600 | Print quality | Very large | Ultra |
PPT Size Presets
| Aspect Ratio | Width x Height (inches) | Description |
|---|---|---|
| 16:9 (Recommended) | 10 x 5.625 | Standard widescreen |
| 4:3 | 10 x 7.5 | Traditional format |
| A4 | 8.27 x 11.69 | For printing |
Examples
Example 1: Quick Conversion
from pdf2ppt import pdf_to_ppt
# Default settings (300 DPI, auto-fit)
pdf_to_ppt("presentation.pdf")
Example 2: Custom Settings
from pdf2ppt import PDF2PPT
# Create converter
converter = PDF2PPT(
pdf_path="presentation.pdf",
output_ppt="high_quality.pptx",
dpi=300,
crop_whitespace=False # Don't crop white borders
)
# Convert
converter.convert_pdf_to_images()
converter.create_ppt(width=10, height=5.625) # 16:9 ratio
Example 3: Batch Convert with Different DPI
from pdf2ppt import pdf_to_ppt
pdfs = ["doc1.pdf", "doc2.pdf", "doc3.pdf"]
for pdf in pdfs:
# Low DPI for preview
pdf_to_ppt(pdf, pdf.replace(".pdf", "_preview.pptx"), dpi=150)
# High DPI for formal use
pdf_to_ppt(pdf, pdf.replace(".pdf", "_hq.pptx"), dpi=300)
Troubleshooting
Issue 1: "Unable to get page count"
Cause: Poppler not installed or not in PATH
Solution: Follow the poppler installation instructions above
Issue 2: Out of Memory
Cause: DPI too high causing large images
Solution: Lower DPI (e.g., 150-200)
Issue 3: Blurry Images
Cause: DPI too low
Solution: Increase DPI (recommended: 300)
Development
Clone Repository
git clone https://github.com/yourusername/pdf2ppt-converter.git
cd pdf2ppt-converter
Install Development Dependencies
pip install -e ".[dev]"
Run Tests
pytest tests/
License
MIT License - see LICENSE file for details
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
This project is built on these excellent open-source libraries:
- pdf2image - PDF to image conversion
- python-pptx - PowerPoint generation
- Pillow - Image processing
- NumPy - Numerical computing
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pdf2ppt_converter-1.0.1.tar.gz.
File metadata
- Download URL: pdf2ppt_converter-1.0.1.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
775e0458bae75422d8a91a72eccef24fbcf8a6493a0e8bbabc4b756e987ec16f
|
|
| MD5 |
e979b7434f8ea098d3c34a05a012f123
|
|
| BLAKE2b-256 |
1205a9283603dc4e5ee57d529e51ec0a514a249a026e5bc10374d33a9a33ad81
|
File details
Details for the file pdf2ppt_converter-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pdf2ppt_converter-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffc42abf02e75a68c4cd5fa256c4182a30b36e5161b79855e67e9264ced4e235
|
|
| MD5 |
4ad8af6c430be8d4835a501082ed4d08
|
|
| BLAKE2b-256 |
35a88f37a04d1d2f70edc5f27c6abfff29a52590e8bc3a65ff8b9f1fee66d427
|