pptx

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package pptx provides a pure-Go writer for PowerPoint (.pptx / OOXML) presentations. It builds the Office Open XML package (a ZIP archive of XML parts) directly, without depending on any third-party Office libraries, so that slidown can remain MIT licensed.

The package is intentionally low level: it knows how to assemble the fixed structural parts of a presentation (content types, relationships, the presentation part, a slide master, a slide layout and a theme) and how to emit individual slide parts. Higher level mapping from slidown's internal slide model is handled by the renderer that builds on top of this package.

Index

Constants

View Source
const (
	// EMUPerInch is the number of EMUs in one inch.
	EMUPerInch = 914400
	// EMUPerPoint is the number of EMUs in one typographic point.
	EMUPerPoint = 12700
	// EMUPerCentimeter is the number of EMUs in one centimeter.
	EMUPerCentimeter = 360000
)

English Metric Units (EMU) helpers. OOXML (and the Google Slides API) measure distances in EMUs, where 914400 EMU == 1 inch == 914400/72 points.

View Source
const (
	DefaultSlideWidth  int64 = 12192000
	DefaultSlideHeight int64 = 6858000
)

Default 16:9 slide dimensions in EMUs (13.333in x 7.5in), matching the PowerPoint "Widescreen" default.

Variables

This section is empty.

Functions

func CoreTitleFromBytes added in v0.0.3

func CoreTitleFromBytes(data []byte) string

CoreTitleFromBytes returns the dc:title recorded in the in-memory .pptx bytes.

func Inches

func Inches(v float64) int64

Inches converts a measurement in inches to EMUs.

func MergeReusingUnchangedShapes added in v0.0.4

func MergeReusingUnchangedShapes(pkg []byte, existingPath string, targets map[int]string) ([]byte, error)

MergeReusingUnchangedShapes rewrites, within pkg, the slides named by targets (a map of new 1-based slide position -> existing slide part name) so that each unchanged text box is restored from the existing slide while the rest of the slide (changed shapes, pictures, tables, relationships, media) stays as freshly generated. Slides not in targets are left untouched.

func MergeReusingUnchangedSlides

func MergeReusingUnchangedSlides(existingPath string, newPPTX []byte, reuse map[int]string) ([]byte, error)

MergeReusingUnchangedSlides builds the output package from the freshly generated newPPTX, but restores the existing file's slide for each entry in reuse, a map of new 1-based slide position -> existing slide part name (e.g. "ppt/slides/slide3.xml"). Using the part name directly avoids the filename-vs-visible-position confusion that arises when slides have been reordered in PowerPoint (sldIdLst order ≠ filename order). The restored slide (its XML, relationships, any notes slide it references and the media those parts use) is copied to the new position, rewriting the notes<->slide cross references when the position changes.

This preserves slides whose source did not change (or that are frozen) even when other slides are inserted, deleted or reordered, identifying them by their stable key rather than by position.

func MergeWithExisting

func MergeWithExisting(existingPath string, newPPTX []byte) ([]byte, error)

MergeWithExisting merges a newly generated pptx package with the contents of an existing pptx file. Entries that are unchanged keep their previous payloads and any old entries missing from the new package are preserved, except for parts under the namespaces slidown fully regenerates (see isRegeneratedPart): those old-only parts are stale design/content leftovers and are dropped so they cannot accumulate across rebuilds and corrupt the package. This keeps the update path stable for slidown-generated decks without requiring a fragile reverse parser.

func Points

func Points(v float64) int64

Points converts a measurement in points to EMUs.

func ReadCoreTitle added in v0.0.3

func ReadCoreTitle(path string) string

ReadCoreTitle returns the dc:title recorded in a .pptx file's docProps/core.xml, or "" when absent or unreadable.

func ReplaceCoreProps added in v0.0.3

func ReplaceCoreProps(existingPath string, newPPTX []byte) ([]byte, error)

ReplaceCoreProps returns the existing pptx package with its docProps/core.xml replaced by the one from the freshly generated newPPTX, preserving every other part verbatim (slides, media, customXml, thumbnails, notes, …) and the original part order. It applies a deck-level metadata change (e.g. a new title) when every slide is otherwise reused unchanged, so the update touches as little of the package as possible.

func ShapeOverlap added in v0.0.4

func ShapeOverlap(a, b []ShapeSignature) float64

ShapeOverlap returns the fraction of shapes shared by two slides, matching by (slot key, fingerprint), over the larger shape count. It is 1.0 when the slides have identical shape sets and 0 when they share nothing. The aligner uses it as a confidence gate before merging shapes between a source slide and its existing counterpart.

func ShapeSignaturesByPart added in v0.0.4

func ShapeSignaturesByPart(path string) (map[string][]ShapeSignature, error)

ShapeSignaturesByPart returns the shape signatures of every slide in an on-disk .pptx keyed by the slide's ZIP part name (e.g. ppt/slides/slide3.xml).

func ShapeSignaturesByPosition added in v0.0.4

func ShapeSignaturesByPosition(pkg []byte) (map[int][]ShapeSignature, error)

ShapeSignaturesByPosition returns, for a .pptx package, the shape signatures of every slide keyed by its 1-based position in presentation order.

func StampShapeKeys added in v0.0.5

func StampShapeKeys(pptxBytes []byte) ([]byte, error)

StampShapeKeys stamps stable keys on keyless non-placeholder top-level shapes in every slide part. Stamping is idempotent and only touches shape metadata extensions, which are excluded from source fingerprints.

func StampSlideKeys added in v0.0.4

func StampSlideKeys(pptxBytes []byte, keysByPos map[int]string) ([]byte, error)

StampSlideKeys rewrites the stable key (the k attribute of the slidown fingerprint extension) on each slide of the given .pptx bytes so that it equals the key of the deck source page occupying the same visible position.

keysByPos maps a 1-based visible slide position (presentation order) to the key that slide should carry: a non-empty key is written (adding the extension when the slide carries none, e.g. a slide pasted in from another presentation), and an empty key clears any key the slide currently has. Slides whose position is absent from keysByPos are left untouched.

Treating the deck source as authoritative for keys keeps the embedded key in step with the Markdown after a page's key is renamed or removed (so no orphaned keys accumulate), and stamps a key onto imported slides so that subsequent rebuilds can match them by key rather than by fragile position. Only the extLst is touched, which the source fingerprint does not cover, so stamping never perturbs change detection and is idempotent.

Types

type Alignment

type Alignment string

Alignment enumerates horizontal paragraph alignment values.

const (
	AlignNone   Alignment = ""
	AlignLeft   Alignment = "l"
	AlignCenter Alignment = "ctr"
	AlignRight  Alignment = "r"
)

type Fill added in v0.0.8

type Fill struct {
	Kind  FillKind
	Color string // RRGGBB for FillSolid
	// Alpha is 0..1. For FillSolid it is the fill's own opacity; for
	// FillGradient it is an overall multiplier applied to every gradient stop's
	// alpha (see renderFill/renderGradient).
	Alpha    float64
	Gradient *Gradient // for FillGradient
}

Fill describes the fill style for a custom-geometry shape.

type FillKind added in v0.0.8

type FillKind int

FillKind enumerates fill types for custom-geometry shapes.

const (
	// FillNone means the shape has no fill.
	FillNone FillKind = iota
	// FillSolid means the shape uses a single solid color fill.
	FillSolid
	// FillGradient means the shape uses a gradient fill.
	FillGradient
)

type GeomPath added in v0.0.8

type GeomPath struct {
	Cmds []PathCmd
}

GeomPath is a sequence of path commands.

type GeomShape added in v0.0.8

type GeomShape struct {
	Name string
	// Placement of this shape within the parent group's child coordinate space (EMU).
	X, Y, W, H int64
	// Path coordinate space size (the <a:path w=.. h=..>). Path points use this space.
	PathW, PathH int64
	Paths        []GeomPath
	Fill         Fill
	Stroke       *Stroke // nil => no outline
	// EvenOdd records the source SVG fill rule. PowerPoint custom geometry uses
	// nonzero winding, so writers preserve the field but do not emit XML for it.
	EvenOdd bool
}

GeomShape is a single custom-geometry shape inside a group.

type Gradient added in v0.0.8

type Gradient struct {
	Kind  GradientKind
	Angle float64 // degrees clockwise from 3 o'clock; used for linear
	Stops []GradientStop
}

Gradient describes a linear or radial gradient fill.

type GradientKind added in v0.0.8

type GradientKind int

GradientKind enumerates gradient fill types.

const (
	// GradientLinear is a linear gradient.
	GradientLinear GradientKind = iota
	// GradientRadial is a radial gradient.
	GradientRadial
)

type GradientStop added in v0.0.8

type GradientStop struct {
	Pos   float64 // 0..1 position along the gradient
	Color string  // RRGGBB hex, no '#'
	Alpha float64 // 0..1 (1 = opaque)
}

GradientStop is one color stop in a gradient fill.

type GroupChild added in v0.0.8

type GroupChild struct {
	Geom *GeomShape
	Text *Shape
}

GroupChild is one ordered child of a GroupShape: exactly one of Geom or Text is non-nil. Children preserves document order across geometry and text nodes so their z-order matches the source SVG.

type GroupShape added in v0.0.8

type GroupShape struct {
	Name string
	// Placement on the slide (EMU).
	X, Y, W, H int64
	// Child coordinate space: chOff and chExt. Child shapes (Geoms/Texts) are
	// positioned in this space; PowerPoint scales child space (ChW x ChH) into
	// the group's on-slide W x H.
	ChX, ChY, ChW, ChH int64
	// Children, when non-empty, is the ordered list of child shapes rendered in
	// document order (preferred over Geoms/Texts, which are retained for
	// convenient typed access).
	Children []GroupChild
	Geoms    []*GeomShape
	Texts    []*Shape
}

GroupShape is a <p:grpSp> containing geometry shapes and optional text boxes.

type LayoutInfo

type LayoutInfo struct {
	PartName     string
	Name         string
	Type         string // sldLayout @type, e.g. "title", "obj", "tx", "blank"
	Placeholders []*PlaceholderInfo
	// MasterPart is the slide master part this layout derives from (resolved
	// from the layout's .rels). Used to inherit placeholder geometry that the
	// layout shape itself does not declare.
	MasterPart string
}

LayoutInfo describes a single slide layout from the template.

func (*LayoutInfo) BodyGeometry

func (l *LayoutInfo) BodyGeometry() (x, y, w, h int64, ok bool)

BodyGeometry returns the geometry of the layout's first body placeholder, or false if none has explicit geometry.

type Package added in v0.0.4

type Package struct {
	// contains filtered or unexported fields
}

Package is a .pptx that has been read and inflated once. Callers that need several pieces of information from the same existing file during a single operation (e.g. an apply that reads slide metas, shape signatures and then merges) should open it once and reuse the parsed parts through the methods below, instead of calling the path-based helpers repeatedly and re-inflating the archive each time.

func OpenPackage added in v0.0.4

func OpenPackage(path string) (*Package, error)

OpenPackage reads and inflates a .pptx from disk a single time.

func OpenPackageBytes added in v0.0.5

func OpenPackageBytes(data []byte) (*Package, error)

OpenPackageBytes inflates a .pptx from in-memory bytes.

func (*Package) MergeReusingUnchangedShapes added in v0.0.4

func (p *Package) MergeReusingUnchangedShapes(pkg []byte, targets map[int]string) ([]byte, error)

MergeReusingUnchangedShapes restores unchanged text boxes from this package into the slides of pkg named by targets, mirroring MergeReusingUnchangedShapes.

func (*Package) MergeReusingUnchangedSlides added in v0.0.4

func (p *Package) MergeReusingUnchangedSlides(newPPTX []byte, reuse map[int]string) ([]byte, error)

MergeReusingUnchangedSlides restores this package's slides named by reuse into newPPTX, mirroring MergeReusingUnchangedSlides.

func (*Package) MergeWith added in v0.0.4

func (p *Package) MergeWith(newPPTX []byte) ([]byte, error)

MergeWith merges newPPTX with this existing package, mirroring MergeWithExisting.

func (*Package) ReplaceCoreProps added in v0.0.4

func (p *Package) ReplaceCoreProps(newPPTX []byte) ([]byte, error)

ReplaceCoreProps swaps in newPPTX's docProps/core.xml while keeping every other part of this existing package verbatim, mirroring ReplaceCoreProps.

func (*Package) ShapeSignaturesByPart added in v0.0.4

func (p *Package) ShapeSignaturesByPart() map[string][]ShapeSignature

ShapeSignaturesByPart returns the shape signatures of every slide keyed by its ZIP part name, mirroring ShapeSignaturesByPart.

func (*Package) SlideMetasAndCoreTitle added in v0.0.4

func (p *Package) SlideMetasAndCoreTitle() ([]SlideMeta, string)

SlideMetasAndCoreTitle returns the per-slide slidown metadata (in slide order) and the deck title, mirroring ReadSlideMetasAndCoreTitle.

type Paragraph

type Paragraph struct {
	// Level is the indentation/nesting level (0-based).
	Level int
	// Bullet enables a bullet glyph for the paragraph.
	Bullet bool
	// Numbered, when true together with Bullet, renders an auto-numbered glyph.
	Numbered bool
	Align    Alignment
	Runs     []*Run
}

Paragraph is a single paragraph within a shape's text body.

type PathCmd added in v0.0.8

type PathCmd struct {
	Verb PathVerb
	Pts  []PathPoint
}

PathCmd is one command in a custom-geometry path.

type PathPoint added in v0.0.8

type PathPoint struct{ X, Y int64 }

PathPoint is a point in the GeomShape's path coordinate space.

type PathVerb added in v0.0.8

type PathVerb int

PathVerb enumerates supported path commands for custom geometry.

const (
	// MoveTo moves the current point to one point.
	MoveTo PathVerb = iota
	// LineTo draws a line to one point.
	LineTo
	// CubicTo draws a cubic Bezier curve using control1, control2 and end points.
	CubicTo
	// QuadTo draws a quadratic Bezier curve using control and end points.
	QuadTo
	// ClosePath closes the current subpath.
	ClosePath
)

type Picture

type Picture struct {
	Name string
	// Data is the raw encoded image (PNG/JPEG/GIF).
	Data []byte
	// SVGData, when set, embeds a native SVG alongside Data as the raster
	// fallback via an asvg:svgBlip extension.
	SVGData []byte
	// Ext is the file extension without the dot: "png", "jpeg" or "gif".
	Ext string
	// Geometry in EMUs.
	X, Y, W, H int64
	// Link, when set, makes the picture a hyperlink to the given URL.
	Link string
	// Placeholder, when set (together with IsPlaceholder), binds this picture to
	// a layout picture placeholder by emitting a <p:ph> element under the
	// picture's <p:nvPr>. Typically PlaceholderPic.
	Placeholder PlaceholderType
	// IsPlaceholder marks this picture as filling a placeholder even when
	// Placeholder is the empty type. When true a <p:ph> element is emitted.
	IsPlaceholder bool
	// PlaceholderIdx is the placeholder index; only meaningful for placeholders.
	PlaceholderIdx int
}

Picture is a raster image placed on a slide with explicit EMU geometry.

type PlaceholderInfo

type PlaceholderInfo struct {
	Type string // "title", "ctrTitle", "subTitle", "body", "" (default body)
	// Name is the shape's display name from the layout (the <p:cNvPr name="...">
	// attribute, e.g. "Subtitle 1" or "Content Placeholder 2"). Available for
	// heuristics like HasSubtitleHint.
	Name string
	// Prompt is the concatenated prompt text stored on the layout placeholder
	// (<a:t> within <p:txBody>). PowerPoint persists user-edited prompts here
	// when <p:ph hasCustomPrompt="1"/>. Used by HasSubtitleHint.
	Prompt  string
	Idx     int
	HasGeom bool
	X, Y    int64
	W, H    int64
}

PlaceholderInfo describes a placeholder within a layout.

func (*PlaceholderInfo) HasSubtitleHint

func (p *PlaceholderInfo) HasSubtitleHint() bool

HasSubtitleHint reports whether this placeholder's display name or prompt text contains the substring "subtitle" (case insensitive). It lets users repurpose an ordinary text placeholder as a subtitle target without resorting to XML editing: editing the placeholder name (via PowerPoint's Selection Pane) or its prompt text in the slide master view is enough to opt in.

type PlaceholderType

type PlaceholderType string

PlaceholderType enumerates the OOXML placeholder types relevant to slidown's title/subtitle/body mapping.

const (
	// PlaceholderNone marks a plain (non-placeholder) text box.
	PlaceholderNone PlaceholderType = ""
	// PlaceholderTitle is a standard title placeholder ("title").
	PlaceholderTitle PlaceholderType = "title"
	// PlaceholderCtrTitle is a centered title placeholder ("ctrTitle").
	PlaceholderCtrTitle PlaceholderType = "ctrTitle"
	// PlaceholderSubTitle is a subtitle placeholder ("subTitle").
	PlaceholderSubTitle PlaceholderType = "subTitle"
	// PlaceholderBody is a body placeholder ("body").
	PlaceholderBody PlaceholderType = "body"
	// PlaceholderPic is a picture placeholder ("pic").
	PlaceholderPic PlaceholderType = "pic"
	// PlaceholderClipArt is a clip-art picture placeholder ("clipArt").
	PlaceholderClipArt PlaceholderType = "clipArt"
	// PlaceholderMedia is a media placeholder ("media").
	PlaceholderMedia PlaceholderType = "media"
)

type Presentation

type Presentation struct {
	Width  int64
	Height int64
	Slides []*Slide
	// Title is the presentation title written to the document metadata
	// (docProps/core.xml). Empty leaves the title blank.
	Title string
	// Template, when set, supplies the design (theme, masters, layouts) and the
	// generated slides reference its layouts instead of the built-in one.
	Template *Template
}

Presentation is an in-memory representation of a deck that can be serialized to a .pptx package via WriteTo.

func New

func New() *Presentation

New returns an empty Presentation using the default 16:9 dimensions.

func (*Presentation) AddSlide

func (p *Presentation) AddSlide() *Slide

AddSlide appends a slide and returns it for further configuration.

func (*Presentation) WriteFile

func (p *Presentation) WriteFile(path string) error

WriteFile serializes the presentation to the given path.

func (*Presentation) WriteTo

func (p *Presentation) WriteTo(w io.Writer) (int64, error)

WriteTo serializes the presentation as an OOXML (.pptx) package to w.

type Run

type Run struct {
	Text      string
	Bold      bool
	Italic    bool
	Underline bool
	Strike    bool
	// Code renders the run using a monospace font.
	Code bool
	// Link, when set, makes the run a hyperlink to the given URL.
	Link string
	// FontSize in points; 0 means inherit from the placeholder/theme.
	FontSize float64
	// Color is an RRGGBB hex string (without '#'); empty means inherit.
	Color string
	// BgColor is an RRGGBB hex string (without '#'); empty means no highlight.
	BgColor string
	// FontFamily is an explicit latin typeface; empty means inherit.
	FontFamily string
	// FontAllScripts, when set with FontFamily, applies that typeface to the
	// East Asian (<a:ea>) and complex-script (<a:cs>) slots too, not just latin.
	// SVG font-family applies to every script, so SVG runs set this.
	FontAllScripts bool
	// Baseline is "", "super", or "sub"; non-empty values render superscript/subscript.
	Baseline string
	// PreserveSpace, when true, emits xml:space="preserve" on the run's <a:t> so
	// leading/trailing whitespace (e.g. a separator between SVG text runs) is
	// not stripped by PowerPoint.
	PreserveSpace bool
}

Run is a styled span of text within a paragraph.

type Shape

type Shape struct {
	Name        string
	Placeholder PlaceholderType
	// IsPlaceholder marks this shape as a placeholder even when Placeholder is
	// the empty (default body) type. When false, Placeholder != "" also implies
	// a placeholder.
	IsPlaceholder bool
	// PlaceholderIdx is the placeholder index; only meaningful for placeholders.
	PlaceholderIdx int
	// Role, when set, records slidown's semantic role for this shape (e.g.
	// "subTitle") independent of its underlying OOXML Placeholder type. It is
	// emitted as a slidown extension under <p:nvPr> so future incremental shape
	// updates can match shapes by intent even when the underlying placeholder
	// type is the generic "body". Unknown to PowerPoint; ignored on read by
	// tools that don't recognise the extension.
	Role string
	// Geometry in EMUs. Used for non-placeholder shapes and as an explicit
	// override for placeholders.
	X, Y, W, H int64
	// NoInset, when true, emits a zero-inset text body (lIns/rIns/tIns/bIns=0)
	// so text placed at explicit coordinates (e.g. converted SVG text) is not
	// shifted by DrawingML's default insets.
	NoInset bool
	// NoWrap, when true, sets the text body to wrap="none" so single-line text
	// (e.g. converted SVG text) is not wrapped across multiple lines.
	NoWrap     bool
	Paragraphs []*Paragraph
}

Shape is a text box (optionally a placeholder) positioned on a slide.

type ShapeSignature added in v0.0.4

type ShapeSignature struct {
	SlotKey string
	FP      string
}

ShapeSignature is a shape's slot key and per-shape fingerprint, used by the slide aligner to gauge how similar two slides are before merging shapes.

type Slide

type Slide struct {
	Shapes []*Shape
	// Pictures are raster images placed on the slide.
	Pictures []*Picture
	// Groups are grouped custom-geometry shapes and text boxes placed on the slide.
	Groups []*GroupShape
	// Tables are tables placed on the slide.
	Tables []*Table
	// LayoutName is the template layout name this slide should use. Ignored in
	// built-in (non-template) mode.
	LayoutName string
	// Note is the speaker note text for the slide.
	Note string
	// Fingerprint, when set, is embedded in the slide XML as a slidown
	// extension so an incremental rebuild can detect whether the source
	// content for this slide changed. Empty omits it.
	Fingerprint string
	// Key is the stable per-slide identity (from the markdown page config),
	// embedded alongside the fingerprint so a rebuild can match slides across
	// inserts, deletions and reordering. Empty omits it.
	Key string
	// Hidden marks the slide as skipped in the presentation: it is still
	// generated as a slide part but its sldId entry carries show="0" so
	// PowerPoint hides it during a slideshow.
	Hidden bool
}

Slide is a single slide consisting of positioned shapes and optional speaker notes.

func (*Slide) AddGroup added in v0.0.8

func (s *Slide) AddGroup(g *GroupShape) *GroupShape

AddGroup appends a group shape to the slide and returns it.

func (*Slide) AddPicture

func (s *Slide) AddPicture(p *Picture) *Picture

AddPicture appends a picture to the slide and returns it.

func (*Slide) AddShape

func (s *Slide) AddShape(sh *Shape) *Shape

AddShape appends a shape to the slide and returns it.

func (*Slide) AddTable

func (s *Slide) AddTable(t *Table) *Table

AddTable appends a table to the slide and returns it.

type SlideMeta

type SlideMeta struct {
	Fingerprint string
	Key         string
	// PartName is the ZIP entry path of the slide this meta was read from,
	// e.g. "ppt/slides/slide3.xml". It reflects the actual on-disk filename,
	// which may differ from the visible (sldIdLst) position when slides have
	// been reordered in PowerPoint.
	PartName string
}

SlideMeta is the slidown metadata embedded in a generated slide: its source fingerprint and optional stable key.

func ReadSlideMetas

func ReadSlideMetas(path string) ([]SlideMeta, error)

ReadSlideMetas reads the per-slide slidown metadata embedded in an existing .pptx, returned in slide order. A slide without the metadata (e.g. one re-saved by another tool that dropped the extension) yields a zero SlideMeta at its position.

func ReadSlideMetasAndCoreTitle added in v0.0.3

func ReadSlideMetasAndCoreTitle(path string) ([]SlideMeta, string, error)

ReadSlideMetasAndCoreTitle reads the per-slide slidown metadata and the deck title from docProps/core.xml in a single ZIP parse, returning both together. It is the preferred entry point when the caller needs both values so the on-disk .pptx is only inflated once.

type Stroke added in v0.0.8

type Stroke struct {
	Color string  // RRGGBB
	Alpha float64 // 0..1
	Width int64   // EMU; 0 renders a hairline-safe minimum
	Cap   string  // "rnd", "sq", "flat"; empty => "flat"
	Join  string  // "round", "bevel", "miter"; empty => "round"
	Dash  string  // OOXML preset dash val (e.g. "dash", "sysDot"); empty => solid
}

Stroke describes the outline style for a custom-geometry shape.

type StyleSpec added in v0.0.3

type StyleSpec struct {
	Bold, Italic, Underline, Strike bool
	Color, BgColor, FontFamily      string
	Baseline                        string
}

StyleSpec captures a custom inline style parsed from a template's style layout. Baseline is "", "super", or "sub".

type Table

type Table struct {
	// Geometry in EMUs. Height may be 0 to let it be derived from rows.
	X, Y, W, H int64
	Rows       []*TableRow
	// Style, when non-nil, overrides the default table styling (cell fills,
	// text styles, alignment and borders) parsed from a template's style
	// layout. Nil preserves the built-in hardcoded styling.
	Style *TableStyleSpec
}

Table is a simple grid table positioned on a slide.

type TableBorderSpec added in v0.0.3

type TableBorderSpec struct {
	Color    string
	WidthEMU int64
	Dash     string
	None     bool
}

type TableCell

type TableCell struct {
	Paragraphs []*Paragraph
	Align      Alignment
}

TableCell is a single table cell.

type TableCellStyleSpec added in v0.0.3

type TableCellStyleSpec struct {
	BgColor           string
	Bold, Italic      bool
	Color, FontFamily string
	HAlign, VAlign    string
}

TableCellStyleSpec holds the styling for one table region. Only bold, italic, text color and font family are currently supported for cell text. TODO: extend table cell text styling to full deck parity by also honoring underline, strikethrough, superscript/subscript baseline, highlight/background color and font size (all already expressible on pptx.Run).

type TableRow

type TableRow struct {
	Cells  []*TableCell
	Header bool
}

TableRow is a single row of table cells.

type TableStyleSpec added in v0.0.3

type TableStyleSpec struct {
	HeaderFirstCol  TableCellStyleSpec
	HeaderOtherCols TableCellStyleSpec
	DataFirstCol    TableCellStyleSpec
	DataOtherCols   TableCellStyleSpec

	OuterHorizontal TableBorderSpec
	OuterVertical   TableBorderSpec

	HeaderFirstColRight  TableBorderSpec
	HeaderFirstColBottom TableBorderSpec
	HeaderOtherColRight  TableBorderSpec
	HeaderOtherColBottom TableBorderSpec
	DataFirstColRight    TableBorderSpec
	DataFirstColBottom   TableBorderSpec
	DataOtherColRight    TableBorderSpec
	DataOtherColBottom   TableBorderSpec
}

type Template

type Template struct {

	// Layouts are the parsed slide layouts available in the template.
	Layouts []*LayoutInfo
	// SyntaxStyles maps style-layout keywords to their custom run styles.
	SyntaxStyles map[string]StyleSpec
	// TableStyle holds table styling parsed from the special style layout.
	TableStyle *TableStyleSpec
	// contains filtered or unexported fields
}

Template is a loaded .pptx used as the design base for generated slides. It carries the template's design parts (theme, slide master(s), slide layouts and related parts) verbatim and exposes the layouts so the renderer can map content onto their placeholders.

func LoadTemplate

func LoadTemplate(path string) (*Template, error)

LoadTemplate reads a PowerPoint template package (a .pptx presentation or .potx template) and extracts its reusable design parts. Both formats share the same OOXML structure for theme, slide masters and slide layouts, so the loader treats them interchangeably.

func (*Template) ContentLayout

func (t *Template) ContentLayout() *LayoutInfo

ContentLayout returns the best layout for a content slide (title + body).

func (*Template) EffectiveGeometry added in v0.0.3

func (t *Template) EffectiveGeometry(l *LayoutInfo, ph *PlaceholderInfo) (x, y, w, h int64, ok bool)

EffectiveGeometry returns a placeholder's geometry in EMUs, preferring the geometry declared on the layout shape itself and falling back to the geometry inherited from the layout's slide master (matched by placeholder idx). ok is false when no geometry can be resolved from either source.

func (*Template) LayoutByName

func (t *Template) LayoutByName(name string) *LayoutInfo

LayoutByName returns the layout whose (case-insensitive) name matches, or nil.

func (*Template) TitleLayout

func (t *Template) TitleLayout() *LayoutInfo

TitleLayout returns the best layout for a title slide.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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