Skip to content

Commit

Permalink
Merge pull request #13 from unidoc/rc-v1.12.0
Browse files Browse the repository at this point in the history
Rc v1.12.0
  • Loading branch information
gunnsth authored Jun 16, 2021
2 parents c79533b + ba8f7d6 commit 2e25a0d
Show file tree
Hide file tree
Showing 13 changed files with 339 additions and 4 deletions.
Binary file added document/doc-to-pdf/chart.docx
Binary file not shown.
Binary file added document/doc-to-pdf/chart.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions document/doc-to-pdf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func init() {
}

var filenames = []string{
"chart",
"headers_footers",
"image_square",
"table",
Expand Down
Binary file added document/image-text-wrap/gophercolor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added document/image-text-wrap/image-text-wrap.docx
Binary file not shown.
152 changes: 152 additions & 0 deletions document/image-text-wrap/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// Copyright 2017 FoxyUtils ehf. All rights reserved.
package main

import (
"io/ioutil"
"log"

"github.com/unidoc/unioffice/common"
"github.com/unidoc/unioffice/common/license"
"github.com/unidoc/unioffice/document"
"github.com/unidoc/unioffice/measurement"

"github.com/unidoc/unioffice/schema/soo/wml"
)

const licenseKey = `
-----BEGIN UNIDOC LICENSE KEY-----
Free trial license keys are available at: https://unidoc.io/
-----END UNIDOC LICENSE KEY-----
`

func init() {
err := license.SetLicenseKey(licenseKey, `Company Name`)
if err != nil {
panic(err)
}
}

var lorem = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin lobortis, lectus dictum feugiat tempus, sem neque finibus enim, sed eleifend sem nunc ac diam. Vestibulum tempus sagittis elementum`

func main() {
doc := document.New()
defer doc.Close()

img1, err := common.ImageFromFile("gophercolor.png")
if err != nil {
log.Fatalf("unable to create image: %s", err)
}
img2data, err := ioutil.ReadFile("gophercolor.png")
if err != nil {
log.Fatalf("unable to read file: %s", err)
}
img2, err := common.ImageFromBytes(img2data)
if err != nil {
log.Fatalf("unable to create image: %s", err)
}

img1ref, err := doc.AddImage(img1)
if err != nil {
log.Fatalf("unable to add image to document: %s", err)
}
img2ref, err := doc.AddImage(img2)
if err != nil {
log.Fatalf("unable to add image to document: %s", err)
}

para := doc.AddParagraph()
anchored, err := para.AddRun().AddDrawingAnchored(img1ref)
if err != nil {
log.Fatalf("unable to add anchored image: %s", err)
}

// Drop square text wrap image.
anchored.SetName("Gopher")
anchored.SetSize(2*measurement.Inch, 2*measurement.Inch)
anchored.SetOrigin(wml.WdST_RelFromHPage, wml.WdST_RelFromVTopMargin)
anchored.SetHAlignment(wml.WdST_AlignHCenter)
anchored.SetYOffset(3 * measurement.Inch)
anchored.SetTextWrapSquare(wml.WdST_WrapTextBothSides)

run := para.AddRun()
for i := 0; i < 40; i++ {
run.AddText(lorem)

// drop an inline image in
if i == 13 {
inl, err := run.AddDrawingInline(img1ref)
if err != nil {
log.Fatalf("unable to add inline image: %s", err)
}
inl.SetSize(1*measurement.Inch, 1*measurement.Inch)
}

// Drop image behind text.
if i == 18 {
anchorDraw, err := run.AddDrawingAnchored(img2ref)
if err != nil {
log.Fatalf("unable to add behind text image: %s", err)
}
anchorDraw.SetTextWrapBehindText()
anchorDraw.SetOrigin(wml.WdST_RelFromHColumn, wml.WdST_RelFromVParagraph)
anchorDraw.SetHAlignment(wml.WdST_AlignHUnset)
anchorDraw.SetOffset(2*measurement.Inch, 3*measurement.Inch)
anchorDraw.SetSize(1*measurement.Inch, 1*measurement.Inch)
}

// Drop image in front of text.
if i == 21 {
anchorDraw, err := run.AddDrawingAnchored(img2ref)
if err != nil {
log.Fatalf("unable to add in front of text image: %s", err)
}
anchorDraw.SetTextWrapInFrontOfText()
anchorDraw.SetOrigin(wml.WdST_RelFromHColumn, wml.WdST_RelFromVParagraph)
anchorDraw.SetHAlignment(wml.WdST_AlignHUnset)
anchorDraw.SetOffset(5*measurement.Inch, 4*measurement.Inch)
anchorDraw.SetSize(1*measurement.Inch, 1*measurement.Inch)
}

// Drop image with bottom and top wrap text.
if i == 23 {
anchorDraw, err := run.AddDrawingAnchored(img2ref)
if err != nil {
log.Fatalf("unable to add top and bottom wrap text image: %s", err)
}
anchorDraw.SetTextWrapTopAndBottom()
anchorDraw.SetOrigin(wml.WdST_RelFromHColumn, wml.WdST_RelFromVParagraph)
anchorDraw.SetHAlignment(wml.WdST_AlignHCenter)
anchorDraw.SetYOffset(7 * measurement.Inch)
anchorDraw.SetSize(1*measurement.Inch, 1*measurement.Inch)
}

// Drop image with through wrap text.
if i == 27 {
anchorDraw, err := run.AddDrawingAnchored(img2ref)
if err != nil {
log.Fatalf("unable to add through wrap text image: %s", err)
}
// Create anchor draw option, parameter for options is followImageShape true or false.
anchorDrawOption := document.NewAnchorDrawWrapOptions()
anchorDraw.SetTextWrapThrough(anchorDrawOption)
anchorDraw.SetOrigin(wml.WdST_RelFromHPage, wml.WdST_RelFromVParagraph)
anchorDraw.SetOffset(2*measurement.Inch, 3*measurement.Inch)
anchorDraw.SetSize(1*measurement.Inch, 1*measurement.Inch)
}

// Drop image with tight wrap text.
if i == 30 {
anchorDraw, err := run.AddDrawingAnchored(img2ref)
if err != nil {
log.Fatalf("unable to add tight wrap text image: %s", err)
}
// Create anchor draw option, parameter for options is followImageShape true or false.
anchorDrawOption := document.NewAnchorDrawWrapOptions()
anchorDraw.SetTextWrapTight(anchorDrawOption)
anchorDraw.SetOrigin(wml.WdST_RelFromHPage, wml.WdST_RelFromVParagraph)
anchorDraw.SetOffset(5*measurement.Inch, 2*measurement.Inch)
anchorDraw.SetSize(1*measurement.Inch, 1*measurement.Inch)
}
}
doc.SaveToFile("image-text-wrap.docx")
}
47 changes: 47 additions & 0 deletions document/page-size-and-orientation/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2017 FoxyUtils ehf. All rights reserved.
package main

import (
"github.com/unidoc/unioffice/common/license"
"github.com/unidoc/unioffice/document"
"github.com/unidoc/unioffice/measurement"
"github.com/unidoc/unioffice/schema/soo/wml"
)

const licenseKey = `
-----BEGIN UNIDOC LICENSE KEY-----
Free trial license keys are available at: https://unidoc.io/
-----END UNIDOC LICENSE KEY-----
`

func init() {
err := license.SetLicenseKey(licenseKey, `Company Name`)
if err != nil {
panic(err)
}
}

func main() {
doc := document.New()
defer doc.Close()

// Create paragraph and apply Title style to paragraph.
para := doc.AddParagraph()
run := para.AddRun()
para.SetStyle("Title")
run.AddText("What is Lorem Ipsum?")

// Create paragraph and apply Heading1 style to paragraph.
para = doc.AddParagraph()
para.SetStyle("Heading1")
run = para.AddRun()
run.AddText("Lorem Ipsum is simply dummy text of the printing and typesetting industry.")

// Set page size to paper A4 and orientation to landscape.
// Paper A4 size is 8.3" × 11.7".
// You can set the orientation with wml.ST_PageOrientationLandscape or wml.ST_PageOrientationPortrait,
section := doc.BodySection()
section.SetPageSizeAndOrientation(measurement.Inch*8.3, measurement.Inch*11.7, wml.ST_PageOrientationLandscape)

doc.SaveToFile("page-size-and-orientation.docx")
}
Binary file not shown.
58 changes: 58 additions & 0 deletions document/paragraph-style/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2017 FoxyUtils ehf. All rights reserved.
package main

import (
"github.com/unidoc/unioffice/common/license"
"github.com/unidoc/unioffice/document"
"github.com/unidoc/unioffice/measurement"
"github.com/unidoc/unioffice/schema/soo/wml"
)

const licenseKey = `
-----BEGIN UNIDOC LICENSE KEY-----
Free trial license keys are available at: https://unidoc.io/
-----END UNIDOC LICENSE KEY-----
`

func init() {
err := license.SetLicenseKey(licenseKey, `Company Name`)
if err != nil {
panic(err)
}
}

func main() {
doc := document.New()
defer doc.Close()

// Create paragraph and apply Title style to paragraph.
para := doc.AddParagraph()
run := para.AddRun()
para.SetStyle("Title")
run.AddText("What is Lorem Ipsum?")

// Create paragraph and apply Heading1 style to paragraph.
para = doc.AddParagraph()
para.SetStyle("Heading1")
run = para.AddRun()
run.AddText("Lorem Ipsum is simply dummy text of the printing and typesetting industry.")

// Create custom style named CustomStyle1 for paragraph style.
// Set last boolean parameter to TRUE if you want to make it default for paragraph.
style := doc.Styles
customStyle := style.AddStyle("CustomStyle1", wml.ST_StyleTypeParagraph, false)
customStyle.SetName("Custom Style 1")
// Set spacing of paragraph before and after.
customStyle.ParagraphProperties().SetSpacing(measurement.Inch*1, measurement.Inch*1)
customStyle.ParagraphProperties().SetAlignment(wml.ST_JcBoth)
customStyle.ParagraphProperties().SetFirstLineIndent(measurement.Inch * 2)
// Set line spacing to single, in this case, 12 points is text height.
customStyle.ParagraphProperties().SetLineSpacing(12*measurement.Point, wml.ST_LineSpacingRuleAuto)
// Apply style `CustomStyle1` to paragraph.
para = doc.AddParagraph()
para.SetStyle("CustomStyle1")
run = para.AddRun()
run.AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")

doc.SaveToFile("paragraph-style.docx")
}
Binary file added document/paragraph-style/paragraph-style.docx
Binary file not shown.
79 changes: 78 additions & 1 deletion document/paragraph_spacing_and_indentation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,87 @@ func init() {
func main() {
doc := document.New()

// Create paragraph and set first line indent and line spacing.
p0 := doc.AddParagraph()
p0.AddRun().AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
p0.SetFirstLineIndent(measurement.Inch * 5)
p0.SetLineSpacing(measurement.Millimeter * 15, wml.ST_LineSpacingRuleExact)
p0.SetLineSpacing(measurement.Millimeter*15, wml.ST_LineSpacingRuleExact)

// Create paragraph and set alignment of paragraph to center,
// and set above and below spacing to 2 inch.
// Use wml.ST_JcCenter to set it center,
// use wml.ST_JcRight to set it right,
// use wml.ST_JcLeft to set it left,
// use wml.ST_JcBoth to set it both (justified).
p1 := doc.AddParagraph()
p1.AddRun().AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
p1.SetAlignment(wml.ST_JcCenter)
p1.SetBeforeSpacing(measurement.Inch * 2)
p1.SetAfterSpacing(measurement.Inch * 2)

// Create paragraph and set left indent and add below spacing to 1 inch.
p2 := doc.AddParagraph()
p2.AddRun().AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
p2.SetLeftIndent(measurement.Inch * 3)
p2.SetAfterSpacing(measurement.Inch * 1)

// Create paragraph and set right indent and set above spacing to 1 inch.
p3 := doc.AddParagraph()
p3.AddRun().AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
p3.SetRightIndent(measurement.Inch * 3)
p3.SetBeforeSpacing(measurement.Inch * 1)

// Create paragraph and set above and below spacing with ignore space between if same style.
p4 := doc.AddParagraph()
p4.AddRun().AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
p4.SetBeforeSpacing(measurement.Inch * 1)
p4.SetAfterSpacing(measurement.Inch * 1)
p4.IgnoreSpaceBetweenParagraphOfSameStyle()

// Create paragraph and set outline level 3.
p5 := doc.AddParagraph()
p5.AddRun().AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
p5.SetBeforeSpacing(measurement.Inch * 1)
p5.SetAfterSpacing(measurement.Inch * 1)
p5.SetOutlineLvl(3)

// Create paragraph and set hanging indent 2 inch.
p6 := doc.AddParagraph()
p6.AddRun().AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
p6.SetBeforeSpacing(measurement.Inch * 2)
p6.SetAfterSpacing(measurement.Inch * 2)
p6.SetHangingIndent(measurement.Inch * 2)

// singlePoint is constant of the text height, it's 12 points.
const singlePoint measurement.Distance = 12

// Create paragraph and set line spacing to single.
p7 := doc.AddParagraph()
p7.AddRun().AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
p7.SetBeforeSpacing(measurement.Inch * 0.5)
p7.SetAfterSpacing(measurement.Inch * 0.5)
p7.SetLineSpacing(1*singlePoint*measurement.Point, wml.ST_LineSpacingRuleAuto)

// Create paragraph and set line spacing to one and half.
p8 := doc.AddParagraph()
p8.AddRun().AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
p8.SetBeforeSpacing(measurement.Inch * 0.5)
p8.SetAfterSpacing(measurement.Inch * 0.5)
p8.SetLineSpacing(1.5*singlePoint*measurement.Point, wml.ST_LineSpacingRuleAuto)

// Create paragraph and set line spacing to double.
p9 := doc.AddParagraph()
p9.AddRun().AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
p9.SetBeforeSpacing(measurement.Inch * 0.5)
p9.SetAfterSpacing(measurement.Inch * 0.5)
p9.SetLineSpacing(2*singlePoint*measurement.Point, wml.ST_LineSpacingRuleAuto)

// Create paragraph and set line spacing to muliple 3.
p10 := doc.AddParagraph()
p10.AddRun().AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
p10.SetBeforeSpacing(measurement.Inch * 0.5)
p10.SetAfterSpacing(measurement.Inch * 0.5)
p10.SetLineSpacing(3*singlePoint*measurement.Point, wml.ST_LineSpacingRuleAuto)

doc.SaveToFile("out.docx")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.13

require (
github.com/go-ole/go-ole v1.2.5
github.com/unidoc/unioffice v1.11.0
github.com/unidoc/unioffice v1.12.0
github.com/unidoc/unipdf/v3 v3.25.0
golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df h1:1RV3lxQ6L6xGFNhngp
github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8=
github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a h1:RLtvUhe4DsUDl66m7MJ8OqBjq8jpWBXPK6/RKtqeTkc=
github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw=
github.com/unidoc/unioffice v1.11.0 h1:WqNDcI+vOtB3waV1pd2hM68ajYRZ50e4DidakQQsWWM=
github.com/unidoc/unioffice v1.11.0/go.mod h1:8QJAWaP6ZNjyoONjKXmzbM07/nDDgHpj5uO7xaBH6Ok=
github.com/unidoc/unioffice v1.12.0 h1:5AjvI1QbNfqcZZ83o2heEsCI43BH4XMrQD+IUKVUgV8=
github.com/unidoc/unioffice v1.12.0/go.mod h1:8QJAWaP6ZNjyoONjKXmzbM07/nDDgHpj5uO7xaBH6Ok=
github.com/unidoc/unipdf/v3 v3.22.0/go.mod h1:WdRz3hVhi/M0jFGXhsT5/9FDyRfga6KgI2ZQqjiOXaM=
github.com/unidoc/unipdf/v3 v3.25.0 h1:OJmfZg2BJdA10oOcb6leyi3lDjeDf5SV1OFlBrBc5+4=
github.com/unidoc/unipdf/v3 v3.25.0/go.mod h1:WdRz3hVhi/M0jFGXhsT5/9FDyRfga6KgI2ZQqjiOXaM=
Expand Down

0 comments on commit 2e25a0d

Please sign in to comment.