forked from unidoc/unioffice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PPT relationships, image fix (unidoc#395)
* PPT relationships, image fix * filenames fix * Custom properties fix * schema update * Table styles fix * Scale fix * path fix * New schema: cycle imports fix * xsdAny namespace duplicate fix * Images names fix * Images extensions fix * duplicate chart fix * chart empty attrs fix * Choice if fixed, scale is rolled back * comments * Rollback license info in schema files * import path fix * import path fix 2 * error with incorrect content types names fixed when deleting slides and then adding them again * template with image example * MustCompile replaced * imports fixed * slideIdx error fix
- Loading branch information
1 parent
9892c32
commit 2052cbb
Showing
29 changed files
with
641 additions
and
74 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/unidoc/unioffice/common" | ||
"github.com/unidoc/unioffice/schema/soo/dml" | ||
"github.com/unidoc/unioffice/schema/soo/pml" | ||
|
||
"github.com/unidoc/unioffice/presentation" | ||
) | ||
|
||
func main() { | ||
startTime := time.Now() | ||
|
||
// Start building pptx | ||
ppt, err := presentation.OpenTemplate("template.potx") | ||
if err != nil { | ||
fmt.Println("presentation.OpenTemplate err ", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Clear out example slides | ||
for _, s := range ppt.Slides() { | ||
if err = ppt.RemoveSlide(s); err != nil { | ||
fmt.Println("ppt.RemoveSlide err ", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// Add new slide from template | ||
layout, err := ppt.GetLayoutByName("Picture with Caption") | ||
if err != nil { | ||
fmt.Println("ppt.GetLayoutByName err ", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Add local image to pptx | ||
image, err := common.ImageFromFile("gophercolor.png") | ||
if err != nil { | ||
fmt.Println("common.ImageFromFile err ", err) | ||
os.Exit(1) | ||
} | ||
|
||
iRef, err := ppt.AddImage(image) | ||
if err != nil { | ||
fmt.Println("ppt.AddImage err ", err) | ||
os.Exit(1) | ||
} | ||
|
||
slide, err := ppt.AddDefaultSlideWithLayout(layout) | ||
if err != nil { | ||
fmt.Println("ppt.AddDefaultSlideWithLayout err ", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Inject content into placeholders | ||
title, _ := slide.GetPlaceholder(pml.ST_PlaceholderTypeTitle) | ||
title.SetText("New title") | ||
|
||
body, _ := slide.GetPlaceholder(pml.ST_PlaceholderTypeBody) | ||
body.SetText("New body text") | ||
|
||
imageRelID := slide.AddImageToRels(iRef) | ||
|
||
pic, err := slide.GetPlaceholder(pml.ST_PlaceholderTypePic) | ||
if err != nil { | ||
fmt.Println("ppt.AddImage err ", err) | ||
os.Exit(1) | ||
} | ||
|
||
spPr := dml.NewCT_ShapeProperties() | ||
spPr.BlipFill = dml.NewCT_BlipFillProperties() | ||
spPr.BlipFill.Blip = dml.NewCT_Blip() | ||
spPr.BlipFill.Blip.EmbedAttr = &imageRelID | ||
spPr.BlipFill.Stretch = dml.NewCT_StretchInfoProperties() // stretch to parent block with default values | ||
|
||
pic.X().SpPr = spPr | ||
|
||
if err := ppt.Validate(); err != nil { | ||
fmt.Println("ppt.Validate err ", err) | ||
} | ||
|
||
if err := ppt.SaveToFile("success.pptx"); err != nil { | ||
fmt.Println("ppt.SaveToFile err ", err) | ||
} | ||
|
||
duration := time.Now().Sub(startTime).Seconds() | ||
fmt.Println("success! took ", duration, " seconds") | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2017 FoxyUtils ehf. All rights reserved. | ||
// | ||
// Use of this source code is governed by the terms of the Affero GNU General | ||
// Public License version 3.0 as published by the Free Software Foundation and | ||
// appearing in the file LICENSE included in the packaging of this file. A | ||
// commercial license can be purchased via https://unidoc.io website. | ||
|
||
package common | ||
|
||
import ( | ||
"github.com/unidoc/unioffice/schema/soo/dml" | ||
) | ||
|
||
// TableStyles contains document specific properties. | ||
type TableStyles struct { | ||
x *dml.TblStyleLst | ||
} | ||
|
||
// NewTableStyles constructs a new TableStyles. | ||
func NewTableStyles() TableStyles { | ||
return TableStyles{x: dml.NewTblStyleLst()} | ||
} | ||
|
||
// X returns the inner wrapped XML type. | ||
func (t TableStyles) X() *dml.TblStyleLst { | ||
return t.x | ||
} | ||
|
||
// DefAttr returns the DefAttr property. | ||
func (t TableStyles) DefAttr() string { | ||
return t.x.DefAttr | ||
} | ||
|
||
// TblStyle returns the TblStyle property. | ||
func (t TableStyles) TblStyle() []*dml.CT_TableStyle { | ||
return t.x.TblStyle | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2017 FoxyUtils ehf. All rights reserved. | ||
// | ||
// Use of this source code is governed by the terms of the Affero GNU General | ||
// Public License version 3.0 as published by the Free Software Foundation and | ||
// appearing in the file LICENSE included in the packaging of this file. A | ||
// commercial license can be purchased via https://unidoc.io website. | ||
|
||
package presentation | ||
|
||
import ( | ||
"github.com/unidoc/unioffice/schema/soo/dml" | ||
"github.com/unidoc/unioffice/schema/soo/pml" | ||
) | ||
|
||
// PresentationProperties contains document specific properties. | ||
type PresentationProperties struct { | ||
x *pml.PresentationPr | ||
} | ||
|
||
// NewPresentationProperties constructs a new PresentationProperties. | ||
func NewPresentationProperties() PresentationProperties { | ||
return PresentationProperties{x: pml.NewPresentationPr()} | ||
} | ||
|
||
// X returns the inner wrapped XML type. | ||
func (p PresentationProperties) X() *pml.PresentationPr { | ||
return p.x | ||
} | ||
|
||
// HtmlPubPr returns the HtmlPubPr property. | ||
func (p PresentationProperties) HtmlPubPr() *pml.CT_HtmlPublishProperties { | ||
return p.x.HtmlPubPr | ||
} | ||
|
||
// WebPr returns the WebPr property. | ||
func (p PresentationProperties) WebPr() *pml.CT_WebProperties { | ||
return p.x.WebPr | ||
} | ||
|
||
// PrnPr returns the PrnPr property. | ||
func (p PresentationProperties) PrnPr() *pml.CT_PrintProperties { | ||
return p.x.PrnPr | ||
} | ||
|
||
// ShowPr returns the ShowPr property. | ||
func (p PresentationProperties) ShowPr() *pml.CT_ShowProperties { | ||
return p.x.ShowPr | ||
} | ||
|
||
// ClrMru returns the ClrMru property. | ||
func (p PresentationProperties) ClrMru() *dml.CT_ColorMRU { | ||
return p.x.ClrMru | ||
} | ||
|
||
// ExtLst returns the ExtLst property. | ||
func (p PresentationProperties) ExtLst() *pml.CT_ExtensionList { | ||
return p.x.ExtLst | ||
} |
Oops, something went wrong.