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 Python. 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
).import os
from aspose_barcode_cloud import ApiClient, EncodeBarcodeType, BarcodeImageFormat, CodeLocation, Configuration
from aspose_barcode_cloud.api.generate_api import GenerateApi
def make_configuration():
env_token = os.getenv("TEST_CONFIGURATION_ACCESS_TOKEN")
if env_token:
config = Configuration(access_token=env_token)
else:
config = Configuration(
client_id="Client Id from https://dashboard.aspose.cloud/applications",
client_secret="Client Secret from https://dashboard.aspose.cloud/applications",
)
return config
def main():
configuration = make_configuration()
api_client = ApiClient(configuration=configuration)
generate_api = GenerateApi(api_client=api_client)
response = generate_api.generate(
EncodeBarcodeType.QR,
"Aspose.BarCode.Cloud",
image_format=BarcodeImageFormat.PNG,
foreground_color="Black",
background_color="White",
resolution=300,
image_height=200,
image_width=200,
text_location=CodeLocation.BELOW,
)
file_name = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "testdata", "qr.png"))
with open(file_name, "wb") as file:
file.write(response.data)
print(f"File '{file_name}' generated.")
if __name__ == "__main__":
main()
Result Image is:
import os
from aspose_barcode_cloud import (
ApiClient,
Configuration,
EncodeBarcodeType,
EncodeDataType,
EncodeData,
GenerateParams,
BarcodeImageParams,
BarcodeImageFormat,
)
from aspose_barcode_cloud.api.generate_api import GenerateApi
def make_configuration():
env_token = os.getenv("TEST_CONFIGURATION_ACCESS_TOKEN")
if env_token:
config = Configuration(access_token=env_token)
else:
config = Configuration(
client_id="Client Id from https://dashboard.aspose.cloud/applications",
client_secret="Client Secret from https://dashboard.aspose.cloud/applications",
)
return config
# Main function to generate barcode
def main():
# Set up the configuration and API client
configuration = make_configuration()
api_client = ApiClient(configuration)
generate_api = GenerateApi(api_client=api_client)
# Define the file path for the generated barcode
file_name = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "testdata", "code39.jpeg"))
# Set up the generation parameters
generate_params = GenerateParams(
barcode_type=EncodeBarcodeType.CODE39,
encode_data=EncodeData(data="Aspose", data_type=EncodeDataType.STRINGDATA),
barcode_image_params=BarcodeImageParams(
foreground_color="#FF0000",
background_color="#FFFF00",
image_format=BarcodeImageFormat.JPEG,
rotation_angle=90,
),
)
# Generate barcode
response = generate_api.generate_body(generate_params)
# Save the generated image to a file
with open(file_name, "wb") as stream:
stream.write(response.data)
print(f"File '{file_name}' generated.")
# To run the main function if this script is executed
if __name__ == "__main__":
main()
Result Image is:
import os
from aspose_barcode_cloud import ApiClient, EncodeBarcodeType, BarcodeImageFormat, CodeLocation, Configuration
from aspose_barcode_cloud.api.generate_api import GenerateApi
def make_configuration():
env_token = os.getenv("TEST_CONFIGURATION_ACCESS_TOKEN")
if env_token:
config = Configuration(access_token=env_token)
else:
config = Configuration(
client_id="Client Id from https://dashboard.aspose.cloud/applications",
client_secret="Client Secret from https://dashboard.aspose.cloud/applications",
)
return config
def main():
file_name = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "testdata", "pdf417.svg"))
api_client = ApiClient(configuration=make_configuration())
generate_api = GenerateApi(api_client=api_client)
# Generate barcode
response = generate_api.generate_multipart(
barcode_type=EncodeBarcodeType.PDF417,
data="Aspose.BarCode.Cloud",
text_location=CodeLocation.ABOVE,
image_format=BarcodeImageFormat.SVG,
)
with open(file_name, "wb") as stream:
stream.write(response.data)
print(f"File '{file_name}' generated.")
if __name__ == "__main__":
main()
Result Image is:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.