Skip to main content

A Streamlit component for rendering PowerPoint presentations using PptxViewJS

Project description

st_pptx_viewer

A powerful and configurable Streamlit component for rendering PowerPoint presentations using the PptxViewJS library.

Features

  • 🎨 Fully Customizable: Control canvas size, toolbar position, colors, and more
  • ⌨️ Keyboard Navigation: Arrow keys and Page Up/Down support
  • 📱 Responsive Design: Automatically adapts to slide aspect ratios
  • 🎯 Easy Integration: Simple API with sensible defaults
  • 🔧 Flexible Configuration: Dataclass-based configuration for type safety
  • Fullscreen Mode: Optional fullscreen viewing
  • 🎭 Custom Styling: Add your own CSS for complete control

Installation

From Source

The module uses CDN-hosted PptxViewJS by default, so no build step is required!

pip install -e ./st_pptx_viewer

Or use the automated installer:

cd st_pptx_viewer
./install.sh

From PyPI

pip install st-pptx-viewer

Quick Start

Basic Usage

import streamlit as st
from st_pptx_viewer import pptx_viewer

st.title("PowerPoint Viewer")

uploaded_file = st.file_uploader("Upload a PPTX file", type=["pptx"])
if uploaded_file:
    pptx_viewer(uploaded_file)

With Configuration

import streamlit as st
from st_pptx_viewer import pptx_viewer, PptxViewerConfig

# Create custom configuration
config = PptxViewerConfig(
    width=1200,
    show_toolbar=True,
    show_slide_counter=True,
    enable_keyboard=True,
    toolbar_position='bottom',
    enable_fullscreen=True,
    canvas_border='2px solid #0066cc',
    canvas_background='#f5f5f5',
)

uploaded_file = st.file_uploader("Upload a PPTX file", type=["pptx"])
if uploaded_file:
    pptx_viewer(uploaded_file, config=config)

From File Path

from pathlib import Path
from st_pptx_viewer import pptx_viewer

# Load from file path
pptx_path = Path("./presentations/demo.pptx")
pptx_viewer(pptx_path)

Configuration Options

The PptxViewerConfig dataclass provides the following options:

Parameter Type Default Description
width int 960 Canvas width in pixels
height int|None None Canvas height (auto-calculated from aspect ratio if None)
show_toolbar bool True Show navigation toolbar
show_slide_counter bool True Show "Slide X / Y" counter
initial_slide int 0 Initial slide index (0-based)
enable_keyboard bool True Enable keyboard navigation
toolbar_position str 'top' Toolbar position: 'top' or 'bottom'
canvas_border str '1px solid #ddd' CSS border style for canvas
canvas_background str '#fff' Background color for canvas
canvas_border_radius int 4 Border radius in pixels
component_height int|None None Total component height (auto-calculated if None)
custom_css str '' Additional custom CSS styles
pptxviewjs_path str|Path|None None Custom path to PptxViewJS.min.js (uses CDN if None)
enable_fullscreen bool False Show fullscreen button
toolbar_style dict {} Custom CSS styles for toolbar

Advanced Examples

Custom Styling

from st_pptx_viewer import pptx_viewer, PptxViewerConfig

config = PptxViewerConfig(
    width=1000,
    toolbar_style={
        'background': 'linear-gradient(to right, #667eea, #764ba2)',
        'color': 'white',
    },
    custom_css="""
        .toolbar button {
            background: white !important;
            color: #667eea !important;
            font-weight: bold;
        }
        .toolbar button:hover {
            background: #f0f0f0 !important;
        }
    """,
    canvas_border='3px solid #667eea',
    canvas_border_radius=12,
)

pptx_viewer(uploaded_file, config=config)

Multiple Presentations

import streamlit as st
from st_pptx_viewer import pptx_viewer, PptxViewerConfig

st.title("Compare Presentations")

col1, col2 = st.columns(2)

with col1:
    st.subheader("Presentation A")
    file_a = st.file_uploader("Upload A", type=["pptx"], key="a")
    if file_a:
        config = PptxViewerConfig(width=500)
        pptx_viewer(file_a, config=config, key="viewer_a")

with col2:
    st.subheader("Presentation B")
    file_b = st.file_uploader("Upload B", type=["pptx"], key="b")
    if file_b:
        config = PptxViewerConfig(width=500)
        pptx_viewer(file_b, config=config, key="viewer_b")

Starting at Specific Slide

config = PptxViewerConfig(
    initial_slide=5,  # Start at slide 6 (0-based index)
    width=1000,
)
pptx_viewer(uploaded_file, config=config)

Minimal Viewer (No Toolbar)

config = PptxViewerConfig(
    show_toolbar=False,
    width=800,
    canvas_border='none',
)
pptx_viewer(uploaded_file, config=config)

Keyboard Shortcuts

When enable_keyboard=True (default), the following shortcuts are available:

  • Arrow Left or Page Up: Previous slide
  • Arrow Right, Page Down, or Space: Next slide

Requirements

  • Python >= 3.8
  • Streamlit >= 1.0.0
  • Internet connection (for CDN-hosted PptxViewJS)

Troubleshooting

CDN Loading Issues

The module uses CDN-hosted PptxViewJS by default. If you have connectivity issues:

  1. Check your internet connection
  2. Check if CDN is accessible: https://cdn.jsdelivr.net/npm/pptxviewjs/dist/PptxViewJS.min.js

Using a local bundle instead:

config = PptxViewerConfig(
    pptxviewjs_path="/path/to/PptxViewJS.min.js"
)

Presentation Not Rendering

  • Ensure the PPTX file is valid and not corrupted
  • Check browser console for JavaScript errors
  • Try with a simpler presentation first

Layout Issues

  • Adjust width and height in configuration
  • Use component_height to control total iframe height
  • Add custom CSS via custom_css parameter

API Reference

pptx_viewer(pptx_file, config=None, key=None)

Main function to render a PPTX file in Streamlit.

Parameters:

  • pptx_file (bytes | BinaryIO | str | Path): PPTX file as bytes, file-like object, or path
  • config (PptxViewerConfig | None): Configuration options
  • key (str | None): Unique component key for Streamlit

Returns: None

PptxViewerConfig

Dataclass for configuration options. See Configuration Options section above.

License

This module is part of the PptxViewJS project. See the main project LICENSE file for details.

Contributing

Contributions are welcome! Please see the main project repository for contribution guidelines.

Related Projects

  • PptxViewJS - The underlying JavaScript library
  • Streamlit - The web framework this component is built for

Support

For issues and questions:

  • GitHub Issues: Report a bug
  • Documentation: See examples in the examples/ directory

Changelog

v1.1.0

  • Improved package maintainability

v1.0.0

  • Initial release
  • Full configuration support
  • Keyboard navigation
  • Fullscreen mode
  • Custom styling options

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

st_pptx_viewer-1.1.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

st_pptx_viewer-1.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file st_pptx_viewer-1.1.0.tar.gz.

File metadata

  • Download URL: st_pptx_viewer-1.1.0.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for st_pptx_viewer-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ae9585f27d993d8e6af4919a04df59edf2ac1153762b582569b7e95b01483595
MD5 c09d4e923ac1fbfe38741b9314d0fd72
BLAKE2b-256 6d77a91fb71391765ffead960b030aeaeb8988170e91db280c7120415694bf20

See more details on using hashes here.

File details

Details for the file st_pptx_viewer-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: st_pptx_viewer-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for st_pptx_viewer-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 232fef0ac294b5eb6d97f389764ac7f59d2e9e785019143a5497bb9ee1e8b748
MD5 30739adc1185414434cebc6c68a6b577
BLAKE2b-256 f690d1472f7dd59b8a6cf9b2e178900d580f0a54c86c159091a0311381f689ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page