pptx

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

pptx is a package to create slide presentations in pptx (Microsoft Power Point) format. A `.pptx` file is just a bunch of zip compressed `.xml` files following the Office Open XML (OOXML) format. To see its content, you can just `unzip <path/to/file>.pptx -d <folder>`. With this package, it is possible to create a `Presentation` and add `Slide`s to it. Then, when saving the presentation, it will generate the required `.xml` files, compress them and write to the disk. Note that this isn't a full implementation of the OOXML format, but a wrapper around it. There's a base template with common files to the presentation and then when saving, the package generate only the slides and relationships. The base template and slide templates were generated using https://python-pptx.readthedocs.io/en/latest/ For more information about OOXML, check http://officeopenxml.com/index.php

Index

Constants

View Source
const HEADER_HEIGHT = 392_471
View Source
const IMAGE_WIDTH = 8_446_273

keep the right aspect ratio: SLIDE_WIDTH / SLIDE_HEIGHT = IMAGE_WIDTH / IMAGE_HEIGHT

View Source
const SLIDE_HEIGHT = 5_143_500
View Source
const SLIDE_WIDTH = 9_144_000

Measurements in OOXML are made in English Metric Units (EMUs) where 1 inch = 914,400 EMUs The intent is to have a measurement unit that doesn't require floating points when dealing with centimeters, inches, points (DPI). Office Open XML (OOXML) http://officeopenxml.com/prPresentation.php https://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/

Variables

View Source
var APP_XML string
View Source
var CONTENT_TYPES_XML string
View Source
var CORE_XML string
View Source
var PPTX_TEMPLATE []byte
View Source
var PRESENTATION_XML string
View Source
var RELS_PRESENTATION_XML string
View Source
var RELS_SLIDE_XML string
View Source
var ROOT_RELS_XML string
View Source
var SLIDEMASTER_RELS_XML string
View Source
var SLIDE_XML string

Functions

func Validate deprecated

func Validate(pptxContent []byte, nSlides int) error

Validate checks that pptxContent contains the structure emitted by D2's PPTX exporter for nSlides.

Deprecated: Validate is a test-only helper specific to D2's output and will be removed after one compatibility release. Downstream tests should validate the ZIP and OOXML properties they rely on directly.

Types

type AppXmlContent

type AppXmlContent struct {
	SlideCount         int
	TitlesOfPartsCount int
	Titles             []string
	D2Version          string
}

type BoardTitle

type BoardTitle struct {
	LinkID      string
	Name        string
	BoardID     string
	LinkToSlide int
}

type ContentTypesXmlContent

type ContentTypesXmlContent struct {
	FileNames []string
}

type CoreXmlContent

type CoreXmlContent struct {
	Title          string
	Subject        string
	Creator        string
	Description    string
	LastModifiedBy string
}
type Link struct {
	ID          string
	Index       int
	Top         int
	Left        int
	Width       int
	Height      int
	SlideIndex  int
	ExternalUrl string
	Tooltip     string
}

type Presentation

type Presentation struct {
	Title       string
	Description string
	Subject     string
	Creator     string
	// D2Version can't have letters, only numbers (`[0-9]`) and `.`
	// Otherwise, it may fail to open in PowerPoint
	D2Version string

	Slides []*Slide
	// contains filtered or unexported fields
}

func NewPresentation

func NewPresentation(title, description, subject, creator, d2Version string, includeNav bool) *Presentation

func (*Presentation) AddSlide

func (p *Presentation) AddSlide(pngContent []byte, titlePath []BoardTitle) (*Slide, error)

func (*Presentation) SaveTo

func (p *Presentation) SaveTo(filePath string) error

type PresentationSlideXmlContent

type PresentationSlideXmlContent struct {
	ID             int
	RelationshipID string
}

type PresentationXmlContent

type PresentationXmlContent struct {
	SlideWidth  int
	SlideHeight int
	Slides      []PresentationSlideXmlContent
}

type RelsPresentationSlideXmlContent

type RelsPresentationSlideXmlContent struct {
	RelationshipID string
	FileName       string
}

type RelsPresentationXmlContent

type RelsPresentationXmlContent struct {
	Slides []RelsPresentationSlideXmlContent
}

type RelsSlideXmlContent

type RelsSlideXmlContent struct {
	FileName       string
	RelationshipID string
	Links          []RelsSlideXmlLinkContent
}

type RelsSlideXmlLinkContent

type RelsSlideXmlLinkContent struct {
	RelationshipID string
	ExternalUrl    string
	SlideIndex     int
}

type Slide

type Slide struct {
	BoardTitle       []BoardTitle
	Links            []*Link
	Image            []byte
	ImageId          string
	ImageWidth       int
	ImageHeight      int
	ImageTop         int
	ImageLeft        int
	ImageScaleFactor float64
}
func (s *Slide) AddLink(link *Link)

type SlideLinkXmlContent

type SlideLinkXmlContent struct {
	ID             int
	RelationshipID string
	Name           string
	Action         string
	Left           int
	Top            int
	Width          int
	Height         int
}

type SlideXmlContent

type SlideXmlContent struct {
	Title        string
	TitlePrefix  []SlideXmlTitlePathContent
	Description  string
	HeaderHeight int
	ImageID      string
	ImageLeft    int
	ImageTop     int
	ImageWidth   int
	ImageHeight  int

	Links []SlideLinkXmlContent
}

type SlideXmlTitlePathContent

type SlideXmlTitlePathContent struct {
	Name           string
	RelationshipID string
}

Jump to

Keyboard shortcuts

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