Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
The Aspose.BarCode Cloud SDK for Go by the GenerateAPI
provides methods to generate barcodes to the []byte. Then you can work with result in order to obtain the desired outcomes. This API supports various barcode formats and configurations, enabling users to customize barcode generation to fit their needs.
[]byte
.Below are examples demonstrating how to save the generated barcode stream to a file.
Generate
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", "Code128.jpeg"))
fileBytes, _, err := client.GenerateAPI.Generate(authCtx, barcode.EncodeBarcodeTypeCode128, "Aspose.BarCode.Cloud", nil)
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)
}
GenerateBody
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", "Pdf417.png"))
imageParams := barcode.BarcodeImageParams{
ForegroundColor: "#FF5733",
BackgroundColor: "#FFFFFF",
ImageFormat: barcode.BarcodeImageFormatJpeg,
}
encodeData := barcode.EncodeData{
Data: "Aspose.BarCode.Cloud",
DataType: barcode.EncodeDataTypeStringData,
}
generateParams := barcode.GenerateParams{
BarcodeType: barcode.EncodeBarcodeTypePdf417,
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)
}
GenerateMultipart
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", "Pdf417.png"))
response, _, err := client.GenerateAPI.GenerateMultipart(authCtx, barcode.EncodeBarcodeTypePdf417, "Aspose.BarCode.Cloud", nil)
if err != nil {
fmt.Printf("Error generating barcode: %v\n", err)
return
}
err = os.WriteFile(fileName, response, 0644)
if err != nil {
fmt.Printf("Error saving barcode to file: %v\n", err)
return
}
fmt.Printf("File '%s' generated.\n", fileName)
}
The Aspose.BarCode Cloud SDK for Go offers a robust solution for generating barcodes in various formats, with flexible configuration options. By using the provided methods, developers can easily create and save barcode images to files, streamlining workflows that require barcode generation. Whether you’re working with simple barcodes like Code128 or more complex ones like QR Codes and DataMatrix, this API provides the tools needed to customize and produce high-quality barcode images.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.