pptx-go

command module
v0.0.0-...-2a9920d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

README

Go-PPTX

A Go library for creating, reading, and modifying PowerPoint (PPTX) files with streaming support for large files.

Features
  • Full PPTX Support: Create, read, and modify PPTX files
  • Streaming I/O: Handle large files efficiently with lazy loading
  • OPC Implementation: Complete Open Packaging Convention implementation
  • Parts Layer: High-level PPTX content handling
    • Presentation, Slide, Master, Layout, Media parts
    • XML namespace handling for OOXML compatibility
    • Shape ID allocation and relationship management
  • Thread Safe: Safe for concurrent use
    • sync/atomic for relationship ID allocation
    • sync.RWMutex for thread-safe operations
    • sync.Map for resource deduplication
  • Zero Dependencies: Only uses Go standard library
Installation
go get github.com/hurtener/pptx-go
Quick Start
Traditional Usage (Small Files)
package main

import (
    "github.com/hurtener/pptx-go/opc"
)

func main() {
    // Open existing file
    pkg, err := opc.OpenFile("presentation.pptx")
    if err != nil {
        panic(err)
    }
    defer pkg.Close()

    // Access parts
    slides := pkg.GetPartsByType(opc.ContentTypeSlide)

    // Save changes
    pkg.SaveFile("output.pptx")
}
Streaming Usage (Large Files)
package main

import (
    "github.com/hurtener/pptx-go/opc"
)

func main() {
    // Open with lazy loading - only metadata is loaded
    pkg, err := opc.OpenStream("large.presentation.pptx")
    if err != nil {
        panic(err)
    }
    defer pkg.Close()

    // Get a part - content not loaded yet
    slide := pkg.GetPart(slideURI)

    // Load only when needed
    if needsModification {
        blob, _ := slide.Blob()  // Now loaded
        // ... modify blob
        slide.SetBlob(modifiedBlob)
    }

    // Stream save - no buffering of complete XML
    pkg.StreamSaveFile("output.pptx")
}
When to Use Which Mode
Scenario Recommended Mode
File size < 10MB Traditional
File size > 50MB Streaming
Only reading metadata Streaming
Modifying many parts Traditional
Modifying few parts Streaming
Random access to all content Traditional
Thread-Safe Relationship ID Allocation

Relationships uses sync/atomic.Int32 for thread-safe relationship ID allocation when multiple goroutines call AddRelationship() concurrently.

// Automatic atomic ID allocation
rels := opc.NewRelationships(sourceURI)
rel1, _ := rels.AddNew(opc.RelTypeSlide, "/ppt/slides/slide1.xml", false)  // rId1
rel2, _ := rels.AddNew(opc.RelTypeSlide, "/ppt/slides/slide2.xml", false)  // rId2

// Preview next ID without consuming
nextID := rels.NextRID()  // "rId3"

// Thread-safe for concurrent calls
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
    wg.Add(1)
    go func() {
        defer wg.Done()
        rels.AddNew(opc.RelTypeSlide, "/ppt/slides/slide.xml", false)
    }()
}
wg.Wait()
// All IDs are unique, no duplicates

Key features:

  • AddNew() uses atomic operations, safe for concurrent calls
  • Counter auto-initializes from existing relationships when loading from XML
  • NextRID() previews the next ID without consuming
Concurrent Streaming (Advanced)

For high-performance scenarios, the library provides concurrent streaming capabilities:

Feature Description
PartDataChannel Channel-based concurrent part writing
ResourceDedupPool sync.Map based image/media deduplication
ConcurrentZipCollector Goroutine-based ZIP writing
ConcurrentStreamSave Worker-based concurrent save

See Streaming Design for detailed documentation.

Documentation
Project Structure
go-pptx/
├── opc/                    # Open Packaging Convention implementation
│   ├── constants.go        # Content types and relationship types
│   ├── packuri.go          # Pack URI handling
│   ├── part.go             # Part and PartCollection
│   ├── package.go          # Traditional Package
│   ├── contenttypes.go     # [Content_Types].xml
│   ├── coreprops.go        # Core properties
│   ├── relation.go         # Relationships
│   ├── stream.go           # Streaming types
│   └── streampkg.go        # Streaming Package
├── parts/                  # PPTX content parts
│   ├── presentation.go     # Presentation part (presentation.xml)
│   ├── slide.go            # Slide part (slideN.xml)
│   ├── slide_types.go      # Slide XML structures
│   ├── master.go           # Slide master
│   ├── master_types.go     # Master XML structures
│   ├── master_cache.go     # Thread-safe master cache
│   ├── media.go            # Media handling
│   ├── media_manager.go    # Media manager with deduplication
│   ├── coreprops.go        # Core properties part
│   ├── relationship.go     # XML relationship structures
│   └── xmlutils.go         # XML namespace utilities
├── test/
│   ├── parts/              # Parts tests
│   ├── utils/              # Test utilities and examples
│   └── pipeline_test.go    # Integration tests
└── docs/
    ├── streaming-design.md # Streaming design documentation
    ├── opc/                # OPC documentation
    │   ├── README.md       # OPC API reference
    │   └── relationship_resolution.md
    └── parts/              # Parts documentation
        ├── presentation.md
        ├── slide.md
        ├── master.md
        ├── media.md
        ├── relationship.md
        └── xmlutils.md
License

MIT License

Documentation

Overview

Package main provides an example usage of the go-pptx library

Directories

Path Synopsis
_gen
genrefdeck command
Command genrefdeck emits a reference .pptx used by the validity layers (LibreOffice headless open-proxy in CI, and the manual per-wave PowerPoint check).
Command genrefdeck emits a reference .pptx used by the validity layers (LibreOffice headless open-proxy in CI, and the manual per-wave PowerPoint check).
genreplica command
Command genreplica reproduces the "Project Management Top Concerns" pitch deck (a real, hand-built Clear Tech deck) using only the pptx builder — a fidelity exercise for the engine.
Command genreplica reproduces the "Project Management Top Concerns" pitch deck (a real, hand-built Clear Tech deck) using only the pptx builder — a fidelity exercise for the engine.
genshowcase command
Command genshowcase emits a single .pptx exercising the full pptx-go surface available today (builder: shapes/fills/lines, rich text, images, sections, notes, tables; scene: every rendered leaf + containers + table).
Command genshowcase emits a single .pptx exercising the full pptx-go surface available today (builder: shapes/fills/lines, rich text, images, sections, notes, tables; scene: every rendered leaf + containers + table).
gentheme command
Command gentheme emits templates/_default-theme.pptx: a minimal package carrying the default theme's theme1.xml, consumed by the scaffold (RFC §7.5).
Command gentheme emits templates/_default-theme.pptx: a minimal package carrying the default theme's theme1.xml, consumed by the scaffold (RFC §7.5).
assets
frames
Package frames holds the curated device-frame shape recipes (RFC §14.3).
Package frames holds the curated device-frame shape recipes (RFC §14.3).
icons
Package icons embeds the curated icon set (RFC §14.1, D-005): lucide-style glyphs authored as single-path, solid-fill SVGs.
Package icons embeds the curated icon set (RFC §14.1, D-005): lucide-style glyphs authored as single-path, solid-fill SVGs.
ornaments
Package ornaments holds the curated preset ornament shape recipes (RFC §14.2, D-005).
Package ornaments holds the curated preset ornament shape recipes (RFC §14.2, D-005).
examples
compose-a-scene command
Command compose-a-scene builds a typed scene IR and renders it to a deck.
Command compose-a-scene builds a typed scene IR and renders it to a deck.
define-a-theme command
Command define-a-theme shows the pptx-go token system (P2) end to end: how to construct a Theme two ways, how to fill shapes and type text runs with semantic tokens, and how the SAME builder input re-skins when it is rendered under a different theme.
Command define-a-theme shows the pptx-go token system (P2) end to end: how to construct a Theme two ways, how to fill shapes and type text runs with semantic tokens, and how the SAME builder input re-skins when it is rendered under a different theme.
embed-a-chart-raster command
Command embed-a-chart-raster demonstrates placing a chart in a deck as a caller-rasterized image.
Command embed-a-chart-raster demonstrates placing a chart in a deck as a caller-rasterized image.
embed-a-code-block-raster command
Command embed-a-code-block-raster demonstrates placing a source-code listing in a deck as a caller-rendered raster.
Command embed-a-code-block-raster demonstrates placing a source-code listing in a deck as a caller-rendered raster.
extend-the-icon-set command
Command extend-the-icon-set registers a caller-supplied SVG icon and uses it in a scene.
Command extend-the-icon-set registers a caller-supplied SVG icon and uses it in a scene.
load-a-brand-template command
Command load-a-brand-template demonstrates ingesting an existing .pptx brand kit so a new deck inherits its theme and slide masters/layouts (D-037).
Command load-a-brand-template demonstrates ingesting an existing .pptx brand kit so a new deck inherits its theme and slide masters/layouts (D-037).
register-an-asset command
Command register-an-asset demonstrates supplying caller-rasterized bytes for asset-bearing scene nodes (Image, Chart, CodeBlock, asset Decoration).
Command register-an-asset demonstrates supplying caller-rasterized bytes for asset-bearing scene nodes (Image, Chart, CodeBlock, asset Decoration).
scaffold-a-presentation command
Command scaffold-a-presentation builds a small PPTX deck from scratch with the pptx (Layer 1) builder, then reopens it to confirm a self-authored deck round-trips losslessly (G6).
Command scaffold-a-presentation builds a small PPTX deck from scratch with the pptx (Layer 1) builder, then reopens it to confirm a self-authored deck round-trips losslessly (G6).
internal
conformance
Package conformance validates that an OPC package pptx-go emits is structurally sound — independent of the writer/reader round-trip.
Package conformance validates that an OPC package pptx-go emits is structurally sound — independent of the writer/reader round-trip.
coveragecheck
Package coveragecheck implements the mechanical per-package coverage band gate described in CLAUDE.md §11.
Package coveragecheck implements the mechanical per-package coverage band gate described in CLAUDE.md §11.
coveragecheck/cmd/coveragecheck command
Command coveragecheck runs the pptx-go per-package coverage band gate.
Command coveragecheck runs the pptx-go per-package coverage band gate.
ooxml
Package ooxml holds shared OOXML helpers used across the per-part-family subpackages (presentation, slide, theme, core, chart, relations, media).
Package ooxml holds shared OOXML helpers used across the per-part-family subpackages (presentation, slide, theme, core, chart, relations, media).
ooxml/drawing
Package drawing is a placeholder for DrawingML wire types (shapes, fills, geometries, text bodies) per RFC §6.2.
Package drawing is a placeholder for DrawingML wire types (shapes, fills, geometries, text bodies) per RFC §6.2.
ooxml/embeddings
Package embeddings holds the wire constants and helpers for embedding font data in a PPTX: the *.fntdata parts and the relationship that ties them to presentation.xml's <p:embeddedFontLst> (RFC §7.6, D-019).
Package embeddings holds the wire constants and helpers for embedding font data in a PPTX: the *.fntdata parts and the relationship that ties them to presentation.xml's <p:embeddedFontLst> (RFC §7.6, D-019).
opc
Package opc provides a Go implementation of the OOXML Open Packaging Convention (OPC), used for processing Office Open XML file formats such as PPTX.
Package opc provides a Go implementation of the OOXML Open Packaging Convention (OPC), used for processing Office Open XML file formats such as PPTX.
render
Package render holds builder-internal rendering helpers that sit below the public pptx API but above the OOXML wire types.
Package render holds builder-internal rendering helpers that sit below the public pptx API but above the OOXML wire types.
Package pptx provides a high-level API for authoring PPTX files.
Package pptx provides a high-level API for authoring PPTX files.
Package scene is Layer 2 of pptx-go: a typed scene IR and a Render entrypoint that composes the pptx builder (Layer 1).
Package scene is Layer 2 of pptx-go: a typed scene IR and a Render entrypoint that composes the pptx builder (Layer 1).
frames
Package frames is the scene-side frame registry: it wires the curated device frames (assets/frames) to their reserved names and provides the per-render caller-extension overlay (RFC §14.4, D-038).
Package frames is the scene-side frame registry: it wires the curated device frames (assets/frames) to their reserved names and provides the per-render caller-extension overlay (RFC §14.4, D-038).
icons
Package icons is the scene-side icon registry: it wires the curated icon set (assets/icons) to their names and provides the per-render caller-extension overlay (RFC §14.1/§14.4, D-005, D-040).
Package icons is the scene-side icon registry: it wires the curated icon set (assets/icons) to their names and provides the per-render caller-extension overlay (RFC §14.1/§14.4, D-005, D-040).
layout
Package layout is the scene geometry engine (RFC §10.2): deterministic slot division of a parent box into columns and grids.
Package layout is the scene geometry engine (RFC §10.2): deterministic slot division of a parent box into columns and grids.
ornaments
Package ornaments is the scene-side ornament registry: it wires the curated ornament recipes (assets/ornaments) to their names and provides the per-render caller-extension overlay (RFC §14.2/§14.4, D-005, D-038).
Package ornaments is the scene-side ornament registry: it wires the curated ornament recipes (assets/ornaments) to their names and provides the per-render caller-extension overlay (RFC §14.2/§14.4, D-005, D-038).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL