-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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.
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
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
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Copyright 2017 FoxyUtils ehf. All rights reserved. | ||
package main | ||
|
||
import ( | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Copyright 2017 FoxyUtils ehf. All rights reserved. | ||
package main | ||
|
||
import ( | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Copyright 2017 FoxyUtils ehf. All rights reserved. | ||
package main | ||
|
||
import ( | ||
|