-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from unidoc/rc-v1.13.0
Prepare examples for unioffice v1.13.0
- Loading branch information
Showing
23 changed files
with
176 additions
and
4 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.
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,67 @@ | ||
/* | ||
* 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/unipdf/v3/model" | ||
|
||
"github.com/unidoc/unioffice/common/license" | ||
"github.com/unidoc/unioffice/document" | ||
"github.com/unidoc/unioffice/document/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) | ||
} | ||
} | ||
|
||
func main() { | ||
|
||
// register all fonts from the folder | ||
err := convert.RegisterFontsFromDirectory("fonts/PTSans") | ||
if err != nil { | ||
log.Fatalf("Error registering fonts from the folder: %s\n", err) | ||
} | ||
|
||
// register fonts in more precise way | ||
zcoolRegular, err := model.NewCompositePdfFontFromTTFFile("fonts/ZCOOL/ZCOOLXiaoWei-Regular.ttf") | ||
if err != nil { | ||
log.Fatalf("error opening font: %s\n", err) | ||
} | ||
convert.RegisterFont("SimHei", convert.FontStyle_Regular, zcoolRegular) // we can use one font instead of other | ||
|
||
doc, err := document.Open("fonts.docx") | ||
if err != nil { | ||
log.Fatalf("error opening document: %s", err) | ||
} | ||
defer doc.Close() | ||
c := convert.ConvertToPdf(doc) | ||
|
||
err = c.WriteToFile("fonts.pdf") | ||
if err != nil { | ||
log.Fatalf("error converting document: %s", err) | ||
} | ||
} |
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.
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.
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,61 @@ | ||
// Copyright 2017 FoxyUtils ehf. All rights reserved. | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/unidoc/unioffice/common" | ||
"github.com/unidoc/unioffice/common/license" | ||
"github.com/unidoc/unioffice/document" | ||
"github.com/unidoc/unioffice/measurement" | ||
) | ||
|
||
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() | ||
|
||
para := doc.AddParagraph() | ||
run := para.AddRun() | ||
for i := 0; i < 16; i++ { | ||
run.AddText(lorem) | ||
} | ||
|
||
// Put image watermark to document. | ||
img1, err := common.ImageFromFile("gophercolor.png") | ||
if err != nil { | ||
log.Fatalf("unable to create image: %s", err) | ||
} | ||
|
||
// Add image to document. | ||
img1ref, err := doc.AddImage(img1) | ||
if err != nil { | ||
log.Fatalf("unable to add image to document: %s", err) | ||
} | ||
|
||
// Set watermark to doc. | ||
watermark := doc.AddWatermarkPicture(img1ref) | ||
watermark.SetPictureWashout(true) | ||
|
||
// Get image size and set watermark size. | ||
// SetPictureSize accept parameter image width and image height. | ||
imageSize := img1ref.Size() | ||
watermark.SetPictureSize(int64(imageSize.X*measurement.Point), int64(imageSize.Y*measurement.Point)) | ||
|
||
doc.SaveToFile("watermark-picture.docx") | ||
} |
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,44 @@ | ||
// Copyright 2017 FoxyUtils ehf. All rights reserved. | ||
package main | ||
|
||
import ( | ||
"github.com/unidoc/unioffice/common/license" | ||
"github.com/unidoc/unioffice/document" | ||
) | ||
|
||
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() | ||
|
||
para := doc.AddParagraph() | ||
run := para.AddRun() | ||
for i := 0; i < 16; i++ { | ||
run.AddText(lorem) | ||
} | ||
|
||
// Set watermark to doc. | ||
watermark := doc.AddWatermarkText("TEST") | ||
|
||
// Change style of watermark text. | ||
// Currently having 2 function, | ||
// SetTextStyleBold and SetTextStyleItalic. | ||
watermark.SetTextStyleBold(true) | ||
watermark.SetTextStyleItalic(false) | ||
|
||
doc.SaveToFile("watermark-text.docx") | ||
} |
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.