...

Package pptx

import "oss.terrastruct.com/d2/lib/pptx"
Overview
Index

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

Constants

const HEADER_HEIGHT = 392_471

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

const IMAGE_WIDTH = 8_446_273
const SLIDE_HEIGHT = 5_143_500

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/

const SLIDE_WIDTH = 9_144_000

Variables

var APP_XML string
var CONTENT_TYPES_XML string
var CORE_XML string
var PPTX_TEMPLATE []byte
var PRESENTATION_XML string
var RELS_PRESENTATION_XML string
var RELS_SLIDE_XML string
var SLIDE_XML string

func Validate

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

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
    Created        string
    Modified       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
}