POST /v1/barcode/generate

Attributes

Attributes are case-sensitive and should be inside JSON for POST request. for example: { "url": "https://example.com/file1.pdf" }
AttributeTypeRequiredDefaultDescription
callbackstringNo-The callback URL (or Webhook) used to receive the POST data. see Webhooks & Callbacks. This is only applicable when async is set to true.
namestringNo-File name for the generated output, the input must be in string format.
expirationintegerNo60Set the expiration time for the output link in minutes. After this specified duration, any generated output file(s) will be automatically deleted from PDF.co Temporary Files Storage. The maximum duration for link expiration varies based on your current subscription plan. To store permanent input files (e.g. re-usable images, pdf templates, documents) consider using PDF.co Built-In Files Storage.
inlinebooleanNofalseSet to true to return results inside the response. Otherwise, the endpoint will return a URL to the output file generated.
asyncbooleanNofalseSet async to true for long processes to run in the background, API will then return a jobId which you can use with the Background Job Check endpoint. Also see Webhooks & Callbacks
typestringYesQRCodeSet the barcode type to be used. See available barcode types in the Supported Barcode Types
valuestringYes-Set the string value to encode inside the barcode, must be in a string format.
decorationImagestringNo-Set this to the image that you want to be inserted the logo inside the QR-Code barcode. To use your file please upload it first to the temporary storage, see the Upload Files section.
profilesobjectNo-See Profiles for more information.
    outputDataFormatstringNo-If you require your output as base64 format, set this to base64
    AngleintegerNo0See profiles.Angle
    NarrowBarWidthintegerNo3See profiles.NarrowBarWidth
    CaptionFontstringNoArial, 12See profiles.CaptionFont
    DataEncryptionAlgorithmstringNo-Controls the encryption algorithm used for data encryption. See User-Controlled Encryption for more information. The available algorithms are: AES128, AES192, AES256.
    DataEncryptionKeystringNo-Controls the encryption key used for data encryption. See User-Controlled Encryption for more information.
    DataEncryptionIVstringNo-Controls the encryption IV used for data encryption. See User-Controlled Encryption for more information.
    DataDecryptionAlgorithmstringNo-Controls the decryption algorithm used for data decryption. See User-Controlled Encryption for more information. The available algorithms are: AES128, AES192, AES256.
    DataDecryptionKeystringNo-Controls the decryption key used for data decryption. See User-Controlled Encryption for more information.
    DataDecryptionIVstringNo-Controls the decryption IV used for data decryption. See User-Controlled Encryption for more information.

profiles.Angle

Specifies the barcode’s rotation angle as an integer in degrees.

ValueDescription
00 degrees clockwise
190 degrees clockwise
2180 degrees clockwise
3270 degrees clockwise
{
 "profiles": "{'Angle': 3}"
}

profiles.NarrowBarWidth

Specifies the width of the narrow bars in the barcode in pixels.

{
 "profiles": "{'NarrowBarWidth': 3}"
}

profiles.CaptionFont

Specifies the font and size of the caption text displayed with the barcode.

{
 "profiles": "{'CaptionFont': 'Arial, 12'}"
}

Query parameters

No query parameters accepted.

Responses

ParameterTypeDescription
urlstringDirect URL to the final PDF file stored in S3.
outputLinkValidTillstringTimestamp indicating when the output link will expire
errorbooleanIndicates whether an error occurred (false means success)
statusstringStatus code of the request (200, 404, 500, etc.). For more information, see Response Codes.
namestringName of the output file
creditsintegerNumber of credits consumed by the request
remainingCreditsintegerNumber of credits remaining in the account
durationintegerTime taken for the operation in milliseconds

QRCode Example

Example Payload

To see the request size limits, please refer to the Request Size Limits.
{
  "name": "barcode.png",
  "value": "abcdef123456",
  "type": "QRCode",
  "inline": false,
  "async": false,
  "decorationImage": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/barcode-generator/logo.png"
}

Example Response

To see the main response codes, please refer to the Response Codes page.
{
  "url": "https://pdf-temp-files.s3.amazonaws.com/72bc579b37844d9f9e63ce06de5196d8/barcode.png",
  "error": false,
  "status": 200,
  "name": "barcode.png",
  "duration": 380,
  "remainingCredits": 98725598,
  "credits": 7
}

Example CURL

curl --location --request POST 'https://api.pdf.co/v1/barcode/generate' \
--header 'Content-Type: application/json' \
--header 'x-api-key: *******************' \
--data-raw '{
"name": "barcode.png",
"value": "abcdef123456",
"type": "QRCode",
"inline": false,
"async": false
}'

QRCode with Logo Inside Example

Example Payload

To see the request size limits, please refer to the Request Size Limits.
{
  "name": "barcode.png",
  "value": "abcdef123456",
  "type": "QRCode",
  "inline": true,
  "async": false
}

Example Response

To see the main response codes, please refer to the Response Codes page.
{
  "url": "https://pdf-temp-files.s3.amazonaws.com/9a87556a8b9e4f4eae60843e697250d4/barcode.png",
  "error": false,
  "status": 200,
  "name": "barcode.png",
  "remainingCredits": 60631
}

Example CURL

curl --location --request POST 'https://api.pdf.co/v1/barcode/generate' \
--header 'Content-Type: application/json' \
--header 'x-api-key: *******************' \
--data-raw '{
"name": "barcode.png",
"value": "abcdef123456",
"type": "QRCode",
"inline": false,
"async": false,
"decorationImage": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/barcode-generator/logo.png"
}'

Data URI as Output Example

Example Payload

To see the request size limits, please refer to the Request Size Limits.
{
  "name": "barcode.png",
  "value": "abcdef123456",
  "type": "QRCode",
  "inline": false,
  "async": false
}

Example Response

To see the main response codes, please refer to the Response Codes page.
{
  "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAABLCAYAAAA4TnrqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAOlSURBVHhe7ZBBimMxEMVy/0v34CELkSmBjH96NhaIwKtXlY9fP5fMfawN7mNtcB9rg/tYG9zH2kAf6/V6Pa5hHeaUTPNTjftYg8Z9rEEjPdYJdoc5JZaT0imUOzopywW7w5wSy0npFModnZTlgt1hTonlpHQK5Y5ObJm5SUpODeuU3CSWE53YMnOTlJwa1im5SSwnOrFl5iYpOTWsU3KTWE50YsvMTWI5sY7lxDrMTWI50YktMzeJ5cQ6lhPrMDeJ5UQntszcJJYT61hOrMPcJJYTndgyc5Ps5ob1S24Sy4lObJm5SXZzw/olN4nlRCe2zNwku7lh/ZKbxHKik7JcsDuWE3YosXyXckcnZblgdywn7FBi+S7ljk7KcsHuWE7YocTyXcodnXD5Kck38qc0dDIdOZV8I39KQyfTkVPJN/KnNHzyZaaPrP4v7mNtcB9rA/3n6SOXxHLCDiXTfFmY9j4l03xZ0NZ0cEksJ+xQMs2XhWnvUzLNlwVtTQeXxHLCDiXTfFmY9j4l03xZSK3p+JJYTtgxC9Pe0rAOc2qkr5sOLonlhB2zMO0tDeswp0b6uungklhO2DEL097SsA5zaqSvs0PMi8Zuxzyh3En/YIeYF43djnlCuZP+wQ4xLxq7HfOEcmf7H+yo5WS3Q42puySWk9R5/2bsqOVkt0ONqbsklpPUef9m7KjlZLdDjam7JJaT1Hn/fg1+hElKTo3SIaXfLh3AjzBJyalROqT026UD+BEmKTk1SoeUfrv0BdLHHXSYUyN13r+/Tvq4gw5zaqTO+/fXSR930GFOjdR5//4Dl5+SWF7gLiWWk9Ih2uKhpySWF7hLieWkdIi2eOgpieUF7lJiOSkdoq3dQ8bJHe5SY+oujam7NHRSlgsnd7hLjam7NKbu0tBJWS6c3OEuNabu0pi6S0MntszcJJYb7NPCbp+UXZ3YMnOTWG6wTwu7fVJ2dWLLzE1iucE+Lez2SdnViS0zN0nJTWPqVsk0Xxo6sWXmJim5aUzdKpnmS0MntszcJCU3jalbJdN8aejElpmbxPJdyh12KNnNiU5smblJLN+l3GGHkt2c6MSWmZvE8l3KHXYo2c2JTspywe4wp8TywsmuoZee+jO7w5wSywsnu4ZeeurP7A5zSiwvnOwaeol/9pTEcsIONabup8RyQ1s89JTEcsIONabup8RyQ1s89JTEcsIONabup8Ryo7Uuf7mPtcF9rA3uY21wH2uD+1iZn58/9whzEbhRquEAAAAASUVORK5CYII=",
  "error": false,
  "status": 200,
  "name": "barcode.png",
  "duration": 298,
  "remainingCredits": 98725605,
  "credits": 7
}

Example CURL

curl --location --request POST 'https://api.pdf.co/v1/barcode/generate' \
--header 'Content-Type: application/json' \
--header 'x-api-key: *******************' \
--data-raw '{
"name": "barcode.png",
"value": "abcdef123456",
"type": "QRCode",
"inline": true,
"async": false
}'

Code Samples

var https = require("https");

// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co
const API_KEY = "***********************************";

// Result image file name
const DestinationFile = "./barcode.png";
// Barcode type. See valid barcode types in the documentation https://developer.pdf.co
const BarcodeType = "Code128";
// Barcode value
const BarcodeValue = "qweasd123456";

// Prepare request to `Barcode Generator` API endpoint
var queryPath = `/v1/barcode/generate`;

// JSON payload for api request
var jsonPayload = JSON.stringify({
    name: 'barcode.png',
    type: BarcodeType,
    value: BarcodeValue
});

var reqOptions = {
    host: "api.pdf.co",
    path: queryPath,
    method: "POST",
    headers: {
        "x-api-key": API_KEY,
        "Content-Type": "application/json",
        "Content-Length": Buffer.byteLength(jsonPayload, 'utf8')
    }
};


exports.handler = async (event) => {

    let dataString = '';
    const promise_response = await new Promise((resolve, reject) => {

        // Send request
        var postRequest = https.request(reqOptions, (response) => {
            response.on('data', chunk => {
                dataString += chunk;
            });

            response.on('end', () => {
                resolve({
                    statusCode: 200,
                    body: JSON.stringify(JSON.parse(dataString), null, 4)
                });
            });

        }).on("error", (e) => {
            reject({
                statusCode: 500,
                body: 'Something went wrong!'
            });
        });

        // Write request data
        postRequest.write(jsonPayload);
        postRequest.end();
    });

    return promise_response;
};