pptx

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package pptx provides PowerPoint (.pptx) file reading and creation functionality.

Index

Constants

View Source
const (
	EMUPerInch = 914400
	EMUPerPt   = 12700 // Points to EMU (1 point = 1/72 inch)
)

EMU conversion constants (English Metric Units) PowerPoint uses EMUs for positioning: 914400 EMUs = 1 inch

Variables

View Source
var ThemePresets = map[string]Theme{
	"default": {
		Colors: ThemeColors{
			Name:       "Office",
			Dark1:      "000000",
			Light1:     "FFFFFF",
			Dark2:      "44546A",
			Light2:     "E7E6E6",
			Accent1:    "4472C4",
			Accent2:    "ED7D31",
			Accent3:    "A5A5A5",
			Accent4:    "FFC000",
			Accent5:    "5B9BD5",
			Accent6:    "70AD47",
			Hyperlink:  "0563C1",
			FollowLink: "954F72",
		},
		TitleFont: "Calibri Light",
		BodyFont:  "Calibri",
	},
	"dark": {
		Colors: ThemeColors{
			Name:       "Dark",
			Dark1:      "FFFFFF",
			Light1:     "1E1E1E",
			Dark2:      "E0E0E0",
			Light2:     "2D2D2D",
			Accent1:    "61AFEF",
			Accent2:    "E06C75",
			Accent3:    "98C379",
			Accent4:    "E5C07B",
			Accent5:    "C678DD",
			Accent6:    "56B6C2",
			Hyperlink:  "61AFEF",
			FollowLink: "C678DD",
		},
		TitleFont: "Segoe UI",
		BodyFont:  "Segoe UI",
	},
	"light": {
		Colors: ThemeColors{
			Name:       "Light",
			Dark1:      "333333",
			Light1:     "FAFAFA",
			Dark2:      "555555",
			Light2:     "F0F0F0",
			Accent1:    "2196F3",
			Accent2:    "FF5722",
			Accent3:    "9E9E9E",
			Accent4:    "FFC107",
			Accent5:    "03A9F4",
			Accent6:    "4CAF50",
			Hyperlink:  "1976D2",
			FollowLink: "7B1FA2",
		},
		TitleFont: "Arial",
		BodyFont:  "Arial",
	},
	"teal": {
		Colors: ThemeColors{
			Name:       "Teal",
			Dark1:      "FFFFFF",
			Light1:     "023047",
			Dark2:      "E0E0E0",
			Light2:     "034764",
			Accent1:    "219EBC",
			Accent2:    "FFB703",
			Accent3:    "8ECAE6",
			Accent4:    "FB8500",
			Accent5:    "126782",
			Accent6:    "F4D35E",
			Hyperlink:  "8ECAE6",
			FollowLink: "FFB703",
		},
		TitleFont: "Arial Black",
		BodyFont:  "Arial",
	},
	"coral": {
		Colors: ThemeColors{
			Name:       "Coral",
			Dark1:      "2D3436",
			Light1:     "FFF5F5",
			Dark2:      "636E72",
			Light2:     "FFE8E8",
			Accent1:    "E17055",
			Accent2:    "00B894",
			Accent3:    "FDCB6E",
			Accent4:    "6C5CE7",
			Accent5:    "74B9FF",
			Accent6:    "A29BFE",
			Hyperlink:  "0984E3",
			FollowLink: "6C5CE7",
		},
		TitleFont: "Georgia",
		BodyFont:  "Georgia",
	},
}

Predefined themes

Functions

func Create

func Create(outputPath string, slides []SlideContent, opts CreateOptions) error

Create creates a new PowerPoint file with the given slides.

func CreateEnhanced added in v1.2.0

func CreateEnhanced(outputPath string, slides []EnhancedSlide, opts EnhancedCreateOptions) error

CreateEnhanced creates a presentation with full feature support

func CreateFromJSON added in v1.2.0

func CreateFromJSON(outputPath string, jsonData []byte) error

CreateFromJSON creates a presentation from JSON input

func CreateFromText

func CreateFromText(outputPath string, text string, opts CreateOptions) error

CreateFromText creates a simple presentation from text. Each paragraph becomes a slide with the first line as title.

func CreateFromTextEnhanced added in v1.2.0

func CreateFromTextEnhanced(outputPath string, text string, opts EnhancedCreateOptions) error

CreateFromTextEnhanced creates a presentation from text with theme and background options

func ExtractSlideText

func ExtractSlideText(path string, slideNum int) (string, error)

ExtractSlideText extracts text from a specific slide (1-indexed).

func ExtractText

func ExtractText(path string) (string, error)

ExtractText extracts all text content from a PowerPoint file.

func GetThemePresets added in v1.2.0

func GetThemePresets() []string

GetThemePresets returns available theme preset names

func IsPPTX

func IsPPTX(path string) bool

IsPPTX checks if a file path appears to be a PowerPoint file.

func ValidatePPTX

func ValidatePPTX(path string) error

ValidatePPTX checks if a file is a valid PPTX file.

Types

type Background added in v1.2.0

type Background struct {
	Color    string `json:"color,omitempty"` // Solid color (hex without #)
	Gradient *struct {
		Colors []string `json:"colors"` // Gradient colors
		Angle  int      `json:"angle"`  // Gradient angle in degrees
	} `json:"gradient,omitempty"`
	Image string `json:"image,omitempty"` // Background image path
}

Background defines slide background

type CreateOptions

type CreateOptions struct {
	Title   string
	Creator string
	Subject string
}

CreateOptions configures PPTX creation.

type Element added in v1.2.0

type Element struct {
	Type  string        `json:"type"` // "text", "image", "shape"
	Text  *TextElement  `json:"text,omitempty"`
	Image *ImageElement `json:"image,omitempty"`
	Shape *ShapeElement `json:"shape,omitempty"`
}

Element is a union type for slide elements

type EnhancedCreateOptions added in v1.2.0

type EnhancedCreateOptions struct {
	Title       string      `json:"title,omitempty"`
	Creator     string      `json:"creator,omitempty"`
	Subject     string      `json:"subject,omitempty"`
	Theme       string      `json:"theme,omitempty"`       // Theme preset name
	CustomTheme *Theme      `json:"customTheme,omitempty"` // Custom theme definition
	Background  *Background `json:"background,omitempty"`  // Default background for all slides
}

EnhancedCreateOptions extends CreateOptions with theming

type EnhancedSlide added in v1.2.0

type EnhancedSlide struct {
	Title      string      `json:"title,omitempty"`      // Optional title (legacy support)
	Body       string      `json:"body,omitempty"`       // Optional body text (legacy support)
	Background *Background `json:"background,omitempty"` // Slide background
	Elements   []Element   `json:"elements,omitempty"`   // Positioned elements
	Notes      string      `json:"notes,omitempty"`      // Speaker notes
	Layout     string      `json:"layout,omitempty"`     // Layout preset name
}

EnhancedSlide represents a slide with full control over elements

type ImageElement added in v1.2.0

type ImageElement struct {
	Path     string   `json:"path"`              // File path or base64 data URI
	Position Position `json:"position"`          // Position and size
	AltText  string   `json:"altText,omitempty"` // Accessibility text
}

ImageElement represents an image to embed

type Info

type Info struct {
	Path       string `json:"path"`
	SlideCount int    `json:"slideCount"`
	Title      string `json:"title,omitempty"`
	Creator    string `json:"creator,omitempty"`
	Subject    string `json:"subject,omitempty"`
	Created    string `json:"created,omitempty"`
	Modified   string `json:"modified,omitempty"`
	Error      string `json:"error,omitempty"`
}

Info contains metadata about a PowerPoint presentation.

func GetInfo

func GetInfo(path string) (*Info, error)

GetInfo returns metadata about a PowerPoint file.

type Position added in v1.2.0

type Position struct {
	X      float64 `json:"x"`      // X position in inches from left
	Y      float64 `json:"y"`      // Y position in inches from top
	Width  float64 `json:"width"`  // Width in inches (0 = auto)
	Height float64 `json:"height"` // Height in inches (0 = auto)
}

Position represents element positioning in inches

func (Position) ToEMU added in v1.2.0

func (p Position) ToEMU() (x, y, cx, cy int64)

ToEMU converts position to EMU values

type PresentationInput added in v1.2.0

type PresentationInput struct {
	Options EnhancedCreateOptions `json:"options,omitempty"`
	Slides  []EnhancedSlide       `json:"slides"`
}

PresentationInput is the JSON input format for full control

func ParseJSONInput added in v1.2.0

func ParseJSONInput(data []byte) (*PresentationInput, error)

ParseJSONInput parses JSON input for presentation creation

type ShapeElement added in v1.2.0

type ShapeElement struct {
	Type      string   `json:"type"`                // "rectangle", "line", "oval"
	Position  Position `json:"position"`            // Position and size
	FillColor string   `json:"fillColor,omitempty"` // Fill color (hex)
	LineColor string   `json:"lineColor,omitempty"` // Border/line color (hex)
	LineWidth float64  `json:"lineWidth,omitempty"` // Line width in points
}

ShapeElement represents a shape (rectangle, line, etc.)

type Slide

type Slide struct {
	Number int    `json:"number"`
	Title  string `json:"title,omitempty"`
	Text   string `json:"text"`
}

Slide represents a single slide in the presentation.

func GetSlides

func GetSlides(path string) ([]Slide, error)

GetSlides returns all slides with their content.

func ListSlides

func ListSlides(path string) ([]Slide, error)

ListSlides returns a summary of all slides.

type SlideContent

type SlideContent struct {
	Title string
	Body  string
}

SlideContent represents content for a slide to create.

type TextElement added in v1.2.0

type TextElement struct {
	Content  string    `json:"content"`         // Text content
	Position Position  `json:"position"`        // Position and size
	Style    TextStyle `json:"style,omitempty"` // Text formatting
}

TextElement represents a positioned text box

type TextStyle added in v1.2.0

type TextStyle struct {
	FontFace  string `json:"fontFace,omitempty"`  // Font name (e.g., "Arial", "Calibri")
	FontSize  int    `json:"fontSize,omitempty"`  // Font size in points
	Color     string `json:"color,omitempty"`     // Hex color without # (e.g., "FF0000")
	Bold      bool   `json:"bold,omitempty"`      // Bold text
	Italic    bool   `json:"italic,omitempty"`    // Italic text
	Underline bool   `json:"underline,omitempty"` // Underlined text
	Align     string `json:"align,omitempty"`     // "left", "center", "right"
}

TextStyle defines text formatting options

type Theme added in v1.2.0

type Theme struct {
	Colors    ThemeColors `json:"colors"`
	TitleFont string      `json:"titleFont,omitempty"` // Font for titles
	BodyFont  string      `json:"bodyFont,omitempty"`  // Font for body text
}

Theme defines presentation theming

type ThemeColors added in v1.2.0

type ThemeColors struct {
	Name       string `json:"name"`
	Dark1      string `json:"dk1"`     // Primary dark (usually text)
	Light1     string `json:"lt1"`     // Primary light (usually background)
	Dark2      string `json:"dk2"`     // Secondary dark
	Light2     string `json:"lt2"`     // Secondary light
	Accent1    string `json:"accent1"` // Primary accent
	Accent2    string `json:"accent2"` // Secondary accent
	Accent3    string `json:"accent3"`
	Accent4    string `json:"accent4"`
	Accent5    string `json:"accent5"`
	Accent6    string `json:"accent6"`
	Hyperlink  string `json:"hlink"`
	FollowLink string `json:"folHlink"`
}

ThemeColors defines a color palette

Jump to

Keyboard shortcuts

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