Skip to content

Commit

Permalink
Prepare examples for v1.15.0 (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnsth committed Sep 22, 2021
1 parent aa3c55e commit d54af34
Show file tree
Hide file tree
Showing 32 changed files with 136 additions and 3 deletions.
Binary file modified document/doc-to-pdf/chart.docx
Binary file not shown.
Binary file modified document/doc-to-pdf/headers_footers.docx
Binary file not shown.
Binary file modified document/doc-to-pdf/image_square.docx
Binary file not shown.
Binary file modified document/doc-to-pdf/output/chart.pdf
Binary file not shown.
Binary file modified document/doc-to-pdf/output/headers_footers.pdf
Binary file not shown.
Binary file modified document/doc-to-pdf/output/image_square.pdf
Binary file not shown.
Binary file modified document/doc-to-pdf/output/table.pdf
Binary file not shown.
Binary file modified document/doc-to-pdf/output/text_only_landscape.pdf
Binary file not shown.
Binary file modified document/doc-to-pdf/output/text_only_portrait.pdf
Binary file not shown.
Binary file modified document/doc-to-pdf/output/textbox_anchor.pdf
Binary file not shown.
Binary file modified document/doc-to-pdf/output/textbox_inline.pdf
Binary file not shown.
Binary file modified document/doc-to-pdf/table.docx
Binary file not shown.
Binary file modified document/doc-to-pdf/text_only_landscape.docx
Binary file not shown.
Binary file modified document/doc-to-pdf/text_only_portrait.docx
Binary file not shown.
Binary file modified document/doc-to-pdf/textbox_anchor.docx
Binary file not shown.
Binary file modified document/doc-to-pdf/textbox_inline.docx
Binary file not shown.
68 changes: 68 additions & 0 deletions document/text_extraction_with_numbering/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2020 FoxyUtils ehf. All rights reserved.
package main

import (
"fmt"
"os"

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

func init() {
// Make sure to load your metered License API key prior to using the library.
// If you need a key, you can sign up and create a free one at https://cloud.unidoc.io
err := license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
if err != nil {
panic(err)
}
}

func main() {
doc, err := document.Open("numbered_list.docx")
if err != nil {
panic(err)
}
// To extract the text and work with the formatted info in a simple fashion, you can use:
extracted := doc.ExtractText()
for ei, e := range extracted.Items {
fmt.Println(ei)
fmt.Println("Text:", e.Text)
if e.Run != nil && e.Run.RPr != nil {
runProps := e.Run.RPr
fmt.Println("Bold:", runProps.B != nil)
fmt.Println("Italic:", runProps.I != nil)
if color := runProps.Color; color != nil {
fmt.Printf("Color: #%s\n", runProps.Color.ValAttr)
}
if highlight := runProps.Highlight; highlight != nil {
fmt.Printf("Highlight: %s\n", runProps.Highlight.ValAttr.String())
}
}
if tblInfo := e.TableInfo; tblInfo != nil {
if tc := tblInfo.Cell; tc != nil {
fmt.Println("Row:", tblInfo.RowIndex)
fmt.Println("Column:", tblInfo.ColIndex)
if pr := tc.TcPr; pr != nil {
if pr.Shd != nil {
fmt.Printf("Shade color: #%s\n", pr.Shd.FillAttr)
}
}
}
}
if drawingInfo := e.DrawingInfo; drawingInfo != nil {
fmt.Println("Height in mm:", measurement.FromEMU(drawingInfo.Height)/measurement.Millimeter)
fmt.Println("Width in mm:", measurement.FromEMU(drawingInfo.Width)/measurement.Millimeter)
}
fmt.Println("--------")
}
// document.ExtractTextOptions contains options to include the numbering and it's spacing indent.
// If you want to work with the flattened text, simply use:
fmt.Println("\nFLATTENED:")
fmt.Println(extracted.TextWithOptions(
document.ExtractTextOptions{
WithNumbering: true,
NumberingIndent: " ",
}))
}
Binary file not shown.
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.14.0
github.com/unidoc/unioffice v1.15.0
github.com/unidoc/unipdf/v3 v3.28.0
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,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.14.0 h1:rzDlgznRdE5uCzmeuXOEO/kMXMRMGVeKN1hHUg8Ep4c=
github.com/unidoc/unioffice v1.14.0/go.mod h1:GNSDPZRcSSMRSiZWVJNWH22nFv705ppUQLa1pfbgAAk=
github.com/unidoc/unioffice v1.15.0 h1:pMEL9pXap4Ew+KJj6iP1pyE9VH33PcYYLRlZ9KQC3FI=
github.com/unidoc/unioffice v1.15.0/go.mod h1:GNSDPZRcSSMRSiZWVJNWH22nFv705ppUQLa1pfbgAAk=
github.com/unidoc/unipdf/v3 v3.28.0 h1:flSCHcrfPHbxaSMltbUqk2Kd+2CsYWOiItj8XqRQc4o=
github.com/unidoc/unipdf/v3 v3.28.0/go.mod h1:WdRz3hVhi/M0jFGXhsT5/9FDyRfga6KgI2ZQqjiOXaM=
github.com/unidoc/unitype v0.2.1 h1:x0jMn7pB/tNrjEVjy3Ukpxo++HOBQaTCXcTYFA6BH3w=
Expand Down
Binary file added presentation/convert_to_pdf/chart.pptx
Binary file not shown.
62 changes: 62 additions & 0 deletions presentation/convert_to_pdf/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2017 FoxyUtils ehf. All rights reserved.
/*
* This example showcases PDF generation from docx document with UniOffice package.
*/

package main

import (
"fmt"
"log"
"os"

unipdflicense "github.com/unidoc/unipdf/v3/common/license"

"github.com/unidoc/unioffice/common/license"
"github.com/unidoc/unioffice/presentation"
"github.com/unidoc/unioffice/presentation/convert"
)

func init() {
// Make sure to load your metered License API key prior to using the library.
// If you need a key, you can sign up and create a free one at https://cloud.unidoc.io
err := unipdflicense.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
if err != nil {
fmt.Printf("ERROR: Failed to set metered key: %v\n", err)
fmt.Printf("Make sure to get a valid key from https://cloud.unidoc.io\n")
fmt.Printf("If you don't have one - Grab one in the Free Tier at https://cloud.unidoc.io\n")
panic(err)
}

// This example requires both for unioffice and unipdf.
err = license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
if err != nil {
fmt.Printf("ERROR: Failed to set metered key: %v\n", err)
fmt.Printf("Make sure to get a valid key from https://cloud.unidoc.io\n")
fmt.Printf("If you don't have one - Grab one in the Free Tier at https://cloud.unidoc.io\n")
panic(err)
}
}

var filenames = []string{
"chart",
"picture",
"several_slides",
"table",
}

func main() {
for _, filename := range filenames {
ppt, err := presentation.Open(filename + ".pptx")
if err != nil {
log.Fatalf("error opening document: %s", err)
}
defer ppt.Close()
outputFilename := "output/" + filename
c := convert.ConvertToPdf(ppt)
err = c.WriteToFile(fmt.Sprintf("%s.pdf", outputFilename))
if err != nil {
log.Fatalf("error saving PDF: %s", err)
}
}
}
Binary file added presentation/convert_to_pdf/output/chart.pdf
Binary file not shown.
Binary file added presentation/convert_to_pdf/output/picture.pdf
Binary file not shown.
Binary file not shown.
Binary file added presentation/convert_to_pdf/output/table.pdf
Binary file not shown.
Binary file added presentation/convert_to_pdf/picture.pptx
Binary file not shown.
Binary file added presentation/convert_to_pdf/several_slides.pptx
Binary file not shown.
Binary file added presentation/convert_to_pdf/table.pptx
Binary file not shown.
1 change: 1 addition & 0 deletions presentation/text_extraction/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2017 FoxyUtils ehf. All rights reserved.
package main

import (
Expand Down
1 change: 1 addition & 0 deletions presentation/use-template-with-image/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2017 FoxyUtils ehf. All rights reserved.
package main

import (
Expand Down
1 change: 1 addition & 0 deletions presentation/use-template/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2017 FoxyUtils ehf. All rights reserved.
package main

import (
Expand Down

0 comments on commit d54af34

Please sign in to comment.