Generate barcode without showing the numbers dont work

Hi.
We try to execute following api call to get a barcode, only showing the barcode and no numbers.

example:
https://api.aspose.cloud/v1.1/barcode/generate?text=3616531385416&type=code39&codeLocation=None&format=JPG&resolutionX=300&resolutionY=200&dimensionX=0.3&dimensionY=2&enableChecksum=Default&appsid=DC0C38A5-9FE6-4396-A347-292E6141E31A&signature=URqSYJUHMb8JPdOL9gNeokymDQI

Please provide the correct parameters.

I have as you see in link tried codeLocation=None but i do not work.

image.png (36.2 KB)

Br Jesper

Hello @Itlicensemagasin !
Unfortunately, the 1.1 version you are using is no longer being developed. In version 1.1 there is no possibility to disable text under the barcode. Please switch to version v3.0 Aspose.Barcode Cloud - API References which allows you to generate a code without text. For ease of use we have SDK for different programming languages REST Barcode Generator & Reader API (1D, 2D & Postal Barcodes).
Feel free to ask any questions you have about version 3.0.

@itlicensemagasin
We recommend upgrading to Aspose Cloud API v3.0 to access new features and improvements, such as the ability to hide barcode text on the image. Our support team is ready to assist you with the transition.

Generating a Barcode Without Numbers Using Aspose Cloud API v3.0

You can generate a barcode without numbers using Aspose Cloud API version 3.0 by following these steps.


Step 1: Obtain an Access Token

Before making API requests, obtain an access token (a JWT token with a limited lifetime).

Request Details:

  • Method: POST
  • URL: https://api.aspose.cloud/connect/token
  • Headers:
    • Content-Type: application/x-www-form-urlencoded
  • Body Parameters:
    • grant_type=client_credentials
    • client_id=YOUR_CLIENT_ID
    • client_secret=YOUR_CLIENT_SECRET

Example Using JavaScript Fetch:

Replace 'YOUR_CLIENT_ID' and 'YOUR_CLIENT_SECRET' with your actual Aspose Cloud credentials.

Note: If you are using Node.js v18 or higher, the fetch API is available globally, and you can remove the require('node-fetch') line.

const fetch = require('node-fetch'); // Remove this line if using Node.js v18 or higher

(async () => {
  try {
    const CLIENT_ID = 'YOUR_CLIENT_ID';
    const CLIENT_SECRET = 'YOUR_CLIENT_SECRET';

    // Obtain Access Token
    const response = await fetch('https://api.aspose.cloud/connect/token', {
      method: 'POST',
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
      body: new URLSearchParams({
        grant_type: 'client_credentials',
        client_id: CLIENT_ID,
        client_secret: CLIENT_SECRET,
      }),
    });

    if (!response.ok) {
      throw new Error(`Token request failed: ${response.status} ${response.statusText}`);
    }

    const data = await response.json();
    const ACCESS_TOKEN = data.access_token;
    console.log('Access Token:', ACCESS_TOKEN);
    console.warn('Access Token expires in', data.expires_in / 3600, 'hours');

    // Proceed to Step 2 with ACCESS_TOKEN
  } catch (error) {
    console.error('Error obtaining access token:', error);
  }
})();

Step 2: Generate the Barcode Without Numbers

Use the access token to request the barcode image.

Request Details:

  • Method: GET
  • URL: https://api.aspose.cloud/v3.0/barcode/generate
  • Headers:
    • Authorization: Bearer ACCESS_TOKEN
  • Query Parameters:
    • type=Code128
    • text=3616531385416
    • format=jpg
    • DimensionX=4
    • BarHeight=120
    • TextLocation=None

Example Using JavaScript Fetch:

Replace 'YOUR_ACCESS_TOKEN' with the access token you obtained in Step 1.

const fs = require('fs');
const fetch = require('node-fetch'); // Remove this line if using Node.js v18 or higher

(async () => {
  try {
    const ACCESS_TOKEN = 'YOUR_ACCESS_TOKEN'; // Obtain this from Step 1

    // Prepare Query Parameters
    const params = new URLSearchParams({
      type: 'Code128',
      text: '3616531385416',
      format: 'jpg',
      DimensionX: '4',
      BarHeight: '120',
      TextLocation: 'None',
    });

    // Generate Barcode
    const response = await fetch(`https://api.aspose.cloud/v3.0/barcode/generate?${params}`, {
      method: 'GET',
      headers: {
        Authorization: `Bearer ${ACCESS_TOKEN}`,
      },
    });

    if (!response.ok) {
      throw new Error(`Barcode generation failed: ${response.status} ${response.statusText}`);
    }

    // Save the Image
    const arrayBuffer = await response.arrayBuffer();
    fs.writeFileSync('barcode.jpg', Buffer.from(arrayBuffer));
    console.log('Barcode image saved as barcode.jpg');
  } catch (error) {
    console.error('Error generating barcode:', error);
  }
})();

Important Notes

  • Access Token Usage:

    • Include the Authorization header with your ACCESS_TOKEN in all API requests.
    • The token expires after a few hours; obtain a new one when necessary.
  • Barcode Types:

    • Please note that code39 is not a valid barcode type name. To generate Code39 barcodes, use either Code39Standard or Code39Extended. For a complete list of barcode types supported by version 1.1, refer to the V1.1 Swagger Specification.
    • APIs v1.1 and v3.0 behave differently when unknown type is passed. If an unknown barcode type is provided to version 1.1, the API defaults to generating a Code128 barcode. This can mask errors and potentially lead to unexpected issues in your applications.
    • Version 3.0 API will raise an exception when an unknown barcode type is passed. This ensures that errors are caught early, helping you build more reliable and error-proof services. See V3.0 Swagger specification for details.

Example URL Without Numbers

Here’s the full API endpoint with parameters to generate Code39Standard barcode without numbers:

https://api.aspose.cloud/v3.0/barcode/generate?type=Code39Standard&text=3616531385416&format=jpg&DimensionX=4&BarHeight=120&TextLocation=None

By following these steps, you can generate a barcode image without the numbers displayed, using the Aspose Cloud API version 3.0. Please feel free to reach out to our support team if you have any questions or need assistance with the upgrade process.