Skip to main content

A high-fidelity, two-pass compiler that translates structured SVG metadata into native PowerPoint (.pptx) presentations.

Project description

Python SVG to PPTX Compiler

A high-fidelity, two-pass compiler that translates structured SVG metadata into native PowerPoint (.pptx) presentations. It uses a strictly decoupled Intermediate Representation (IR) layer to bridge SVG semantics with PowerPoint's DrawingML.

Features

  • Decoupled Architecture: Separate Frontend (Parser), IR Layer, and Backend (Generator).
  • Geometric Mapping: Translates SVG shapes (<rect>, <circle>, <ellipse>, <polygon>) into native PowerPoint shapes.
  • Smart Text Handling: Maps nested <text> and <tspan> elements to native text frames with custom styling (font-family, size, weight, color).
  • Intelligent Connectors: Support for straight, elbow, and curve routing with automatic shape anchoring (begin_connect / end_connect).
  • Arrowhead Support: Recognizes standard SVG markers and maps them to PowerPoint's arrow, diamond, and stealth line-end types.
  • Complex Icons: Supports embedding nested <svg> fragments as high-quality pictures.
  • Hierarchical Grouping: Reconstructs SVG group structures (<g>) as native PowerPoint GroupShapes, supporting nested hierarchies.
  • Styling Preservation: Handles hex colors, CSS color names (e.g., orange, blue), stroke widths, corner radii, and translucency (alpha).
  • Logging Implementation: Uses standard Python logging module for production-ready monitoring.

Project Structure

src/surquest/utils/svg2pptx/
├── parser.py           # SVG Parser (Frontend)
├── generator.py        # PPTX Generator (Backend)
├── svg2pptx.py         # Main entry point and orchestration
├── models/             # Intermediate Representation (IR) Layer

Installation

Ensure you have the required dependencies:

pip install python-pptx lxml

Usage

Simple Conversion (Single Slide)

from surquest.utils.svg2pptx import SVG2Pptx

# Initialize converter
converter = SVG2Pptx()

# Convert SVG file/string to PPTX
converter.convert(
    svg_input="input.svg",
    output_path="output.pptx"
)

Multi-Slide Conversion

You can generate a multi-slide presentation by providing a list of SVG paths. The slides will be generated in the order provided.

from surquest.utils.svg2pptx import SVG2Pptx

converter = SVG2Pptx()
converter.convert(
    svg_input=["slide1.svg", "slide2.svg", "slide3.svg"],
    output_path="multi_slide.pptx"
)

Exporting and Importing Intermediate Representation (JSON)

The compiler allows you to export the Intermediate Representation (IR) to JSON, and recreate presentations directly from the JSON. This is particularly useful for debugging or programmatic manipulation before PPTX generation.

from surquest.utils.svg2pptx import SVG2Pptx

converter = SVG2Pptx()

# 1. Export SVG directly to JSON IR
json_string = converter.to_json("input.svg")

# 2. Convert to PPTX and save the JSON IR simultaneously
converter.convert(
    svg_input="input.svg",
    output_path="output.pptx",
    export_as_json=True # Will also generate output.json
)

# 3. Create a presentation from a saved JSON IR
converter.from_json(
    json_input="output.json",
    output_path="restored_presentation.pptx"
)

Advanced Usage (Low-level API)

from surquest.utils.svg2pptx.parser import SVGParser
from surquest.utils.svg2pptx.generator import PPTXBackend

# 1. Parse SVG into Intermediate Representation
parser = SVGParser(svg_source, slide_width=12192000, slide_height=6858000, svg_ns="{http://www.w3.org/2000/svg}")
ir_slide = parser.parse()

# 2. Render IR to PPTX
prs = PPTXBackend([ir_slide]).render()
prs.save("output.pptx")

Development & Testing

Running the Example

You can use the provided run script to process SVG files in the data/ directory:

python scripts/run.py

SVG Metadata Schema & Requirements

The compiler expects SVG files to conform to specific structural and metadata rules to guide the transformation properly:

Canvas & Styling

  • Dimensions: SVG must have viewBox and full widht and height, e.g. viewBox="0 0 960 540" width="100%" height="100%".
  • Styling: Use presentation attributes (fill="#FF5733", stroke="#e0e0e0") ONLY. Do not use inline CSS (style="...") or <style> blocks.
  • Colors & Transparency: Use 3 or 6-digit hex colors. For opacity, use explicit fill-opacity="..." or stroke-opacity="..." attributes (0.0 to 1.0) rather than 8-digit hex codes.
  • Typography: Use standard fonts only (e.g., Arial, Calibri, Segoe UI). Use <tspan> for rich text formatting.

Structural Rules

  • InfoBox (data-element-type="infoBox"): Wrap logical components in <g id="[unique_id]" data-element-type="infoBox">.
  • Connectors (data-element-type="connector"): Must be kept isolated at the root level (never nested inside other <g> groups) as <line> or <polyline>.
    • Required attributes: data-start="[source_id]", data-end="[target_id]", data-connector-type="straight|elbow|curve".
    • Arrowheads: Supported via marker-start and marker-end attributes referencing standard marker defs (none, arrow, diamond, stealth).
  • Icons (data-element-type="icon"): Isolate inside a group and nest a child <svg> with explicit x, y, width, height, and viewBox attributes.

License

This project is licensed under the MIT License.

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

surquest_utils_svg2pptx-0.0.1.tar.gz (43.2 kB view details)

Uploaded Source

Built Distribution

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

surquest_utils_svg2pptx-0.0.1-py2.py3-none-any.whl (24.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file surquest_utils_svg2pptx-0.0.1.tar.gz.

File metadata

  • Download URL: surquest_utils_svg2pptx-0.0.1.tar.gz
  • Upload date:
  • Size: 43.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for surquest_utils_svg2pptx-0.0.1.tar.gz
Algorithm Hash digest
SHA256 085cbddba9a162c26224349a9d5adb8ce39b05cbc9eb62674589a8cc1e41e2af
MD5 83ed7eb62db216a7e3eeea5e22d278bb
BLAKE2b-256 d67ba566d5b58ee4d741e92271149fa55d6f4026f3d8af2ce63e7758557967b1

See more details on using hashes here.

File details

Details for the file surquest_utils_svg2pptx-0.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for surquest_utils_svg2pptx-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 15781768e0a569272b0fdac0d7e5984129207f14ac0e9e0f26f88ae01542a3f7
MD5 95345e301260bbc87dd9f07ff233d829
BLAKE2b-256 9d26640fd4b6b8b5d17c12da6d559311525ac7e707da0eb7cffb5cac18a08bcd

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