Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
This documentation explains how to customize the appearance of barcodes using the Aspose.BarCode Cloud SDK for Go. It provides details on the available methods, customization options, and examples of usage.
When generating a barcode, you can customize various aspects of its appearance using the properties of the request classes.
Key Properties:
QR
, Aztec
, Pdf417
, Code39
, etc).Png
, Jpeg
, Svg
).AliceBlue
or #FF000000
).Below
, Above
, None
).Pixel
, Inch
, Millimeter
).package main
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/antihax/optional"
"github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/v4/barcode"
"github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/v4/barcode/jwt"
)
func makeConfiguration() (*barcode.APIClient, context.Context, error) {
jwtToken := os.Getenv("TEST_JWT_ACCESS_TOKEN")
if jwtToken != "" {
config := barcode.NewConfiguration()
config.AddDefaultHeader("Authorization", "Bearer "+jwtToken)
client := barcode.NewAPIClient(config)
authCtx := context.Background()
return client, authCtx, nil
}
jwtConf := jwt.NewConfig(
"Client Id from https://dashboard.aspose.cloud/applications",
"Client Secret from https://dashboard.aspose.cloud/applications",
)
authCtx := context.WithValue(context.Background(),
barcode.ContextJWT,
jwtConf.TokenSource(context.Background()))
client := barcode.NewAPIClient(barcode.NewConfiguration())
return client, authCtx, nil
}
func Generate(client *barcode.APIClient, authCtx context.Context) error {
fileName, err := filepath.Abs(filepath.Join("testdata", "qr.png"))
opts := &barcode.GenerateAPIGenerateOpts{
ImageFormat: optional.NewInterface(barcode.BarcodeImageFormatPng),
}
fileBytes, _, err := client.GenerateAPI.Generate(authCtx, barcode.EncodeBarcodeTypeQR, "Aspose.BarCode.Cloud", opts)
if err != nil {
return fmt.Errorf("error generating barcode: %v", err)
}
err = os.WriteFile(fileName, fileBytes, 0644)
if err != nil {
return fmt.Errorf("error saving barcode to file: %v", err)
}
fmt.Printf("File '%s' generated.\n", fileName)
return nil
}
func main() {
client, authCtx, err := makeConfiguration()
if err != nil {
fmt.Printf("Error setting up configuration: %v\n", err)
return
}
err = Generate(client, authCtx)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
}
Result Image is:
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/v4/barcode"
"github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/v4/barcode/jwt"
)
func makeConfiguration() (*barcode.APIClient, context.Context, error) {
jwtToken := os.Getenv("TEST_JWT_ACCESS_TOKEN")
if jwtToken != "" {
config := barcode.NewConfiguration()
config.AddDefaultHeader("Authorization", "Bearer "+jwtToken)
client := barcode.NewAPIClient(config)
authCtx := context.Background()
return client, authCtx, nil
}
jwtConf := jwt.NewConfig(
"Client Id from https://dashboard.aspose.cloud/applications",
"Client Secret from https://dashboard.aspose.cloud/applications",
)
authCtx := context.WithValue(context.Background(),
barcode.ContextJWT,
jwtConf.TokenSource(context.Background()))
client := barcode.NewAPIClient(barcode.NewConfiguration())
return client, authCtx, nil
}
func main() {
client, authCtx, err := makeConfiguration()
if err != nil {
fmt.Printf("Error setting up configuration: %v\n", err)
return
}
fileName, err := filepath.Abs(filepath.Join("testdata", "Code39.jpeg"))
imageParams := barcode.BarcodeImageParams{
ForegroundColor: "#FF0000",
BackgroundColor: "#FFFF00",
ImageFormat: barcode.BarcodeImageFormatJpeg,
RotationAngle: 90,
}
encodeData := barcode.EncodeData{
Data: "Aspose",
DataType: barcode.EncodeDataTypeStringData,
}
generateParams := barcode.GenerateParams{
BarcodeType: barcode.EncodeBarcodeTypeCode39,
EncodeData: encodeData,
BarcodeImageParams: imageParams,
}
fileBytes, _, err := client.GenerateAPI.GenerateBody(authCtx, generateParams)
if err != nil {
fmt.Printf("Error generating barcode: %v\n", err)
return
}
err = os.WriteFile(fileName, fileBytes, 0644)
if err != nil {
fmt.Printf("Error saving barcode to file: %v\n", err)
return
}
fmt.Printf("File '%s' generated.\n", fileName)
}
Result Image is:
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/antihax/optional"
"github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/v4/barcode"
"github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/v4/barcode/jwt"
)
func makeConfiguration() (*barcode.APIClient, context.Context, error) {
jwtToken := os.Getenv("TEST_JWT_ACCESS_TOKEN")
if jwtToken != "" {
config := barcode.NewConfiguration()
config.AddDefaultHeader("Authorization", "Bearer "+jwtToken)
client := barcode.NewAPIClient(config)
authCtx := context.Background()
return client, authCtx, nil
}
jwtConf := jwt.NewConfig(
"Client Id from https://dashboard.aspose.cloud/applications",
"Client Secret from https://dashboard.aspose.cloud/applications",
)
authCtx := context.WithValue(context.Background(),
barcode.ContextJWT,
jwtConf.TokenSource(context.Background()))
client := barcode.NewAPIClient(barcode.NewConfiguration())
return client, authCtx, nil
}
func main() {
client, authCtx, err := makeConfiguration()
if err != nil {
fmt.Printf("Error setting up configuration: %v\n", err)
return
}
fileName, err := filepath.Abs(filepath.Join("testdata", "Pdf417.svg"))
fileBytes, _, err := client.GenerateAPI.GenerateMultipart(authCtx, barcode.EncodeBarcodeTypePdf417, "Aspose.BarCode.Cloud", &barcode.GenerateAPIGenerateMultipartOpts{
TextLocation: optional.NewInterface(barcode.CodeLocationAbove),
ImageFormat: optional.NewInterface(barcode.BarcodeImageFormatSvg),
})
if err != nil {
fmt.Printf("Error generating barcode: %v\n", err)
return
}
err = os.WriteFile(fileName, fileBytes, 0644)
if err != nil {
fmt.Printf("Error saving barcode to file: %v\n", err)
return
}
fmt.Printf("File '%s' generated.\n", fileName)
}
Result Image is:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.