Attributes are case-sensitive and should be inside JSON for POST request. for example: { "url": "https://example.com/file1.pdf" }
Attribute
Type
Required
Default
Description
callback
string
No
-
The callback URL (or Webhook) used to receive the POST data. see Webhooks & Callbacks. This is only applicable when async is set to true.
name
string
No
-
File name for the generated output, the input must be in string format.
expiration
integer
No
60
Set 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.
inline
boolean
No
false
Set to true to return results inside the response. Otherwise, the endpoint will return a URL to the output file generated.
Set the string value to encode inside the barcode, must be in a string format.
decorationImage
string
No
-
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.
Controls the encryption algorithm used for data encryption. See User-Controlled Encryption for more information. The available algorithms are: AES128, AES192, AES256.
DataEncryptionKey
string
No
-
Controls the encryption key used for data encryption. See User-Controlled Encryption for more information.
DataEncryptionIV
string
No
-
Controls the encryption IV used for data encryption. See User-Controlled Encryption for more information.
DataDecryptionAlgorithm
string
No
-
Controls the decryption algorithm used for data decryption. See User-Controlled Encryption for more information. The available algorithms are: AES128, AES192, AES256.
DataDecryptionKey
string
No
-
Controls the decryption key used for data decryption. See User-Controlled Encryption for more information.
DataDecryptionIV
string
No
-
Controls the decryption IV used for data decryption. See User-Controlled Encryption for more information.
var https = require("https");// The authentication key (API Key).// Get your own by registering at https://app.pdf.coconst API_KEY = "***********************************";// Result image file nameconst DestinationFile = "./barcode.png";// Barcode type. See valid barcode types in the documentation https://developer.pdf.coconst BarcodeType = "Code128";// Barcode valueconst BarcodeValue = "qweasd123456";// Prepare request to `Barcode Generator` API endpointvar queryPath = `/v1/barcode/generate`;// JSON payload for api requestvar 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;};
var https = require("https");// The authentication key (API Key).// Get your own by registering at https://app.pdf.coconst API_KEY = "***********************************";// Result image file nameconst DestinationFile = "./barcode.png";// Barcode type. See valid barcode types in the documentation https://developer.pdf.coconst BarcodeType = "Code128";// Barcode valueconst BarcodeValue = "qweasd123456";// Prepare request to `Barcode Generator` API endpointvar queryPath = `/v1/barcode/generate`;// JSON payload for api requestvar 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;};
import osimport requests # pip install requests# The authentication key (API Key).# Get your own by registering at https://app.pdf.coAPI_KEY = "******************************************"# Base URL for PDF.co Web API requestsBASE_URL = "https://api.pdf.co/v1"# Result file nameResultFile = ".\\barcode.png"# Barcode type. See valid barcode types in the documentation https://developer.pdf.coBarcodeType = "Code128"# Barcode valueBarcodeValue = "qweasd123456"def main(args = None): generateBarcode(ResultFile)def generateBarcode(destinationFile): """Generates Barcode using PDF.co Web API""" # Prepare requests params as JSON # See documentation: https://developer.pdf.co/api/barcode-generator parameters = {} parameters["name"] = os.path.basename(destinationFile) parameters["type"] = BarcodeType parameters["value"] = BarcodeValue # Prepare URL for 'Barcode Generate' API request url = "{}/barcode/generate".format(BASE_URL) # Execute request and get response as JSON response = requests.post(url, data=parameters, headers={ "x-api-key": API_KEY }) if (response.status_code == 200): json = response.json() if json["error"] == False: # Get URL of result file resultFileUrl = json["url"] # Download result file r = requests.get(resultFileUrl, stream=True) if (r.status_code == 200): with open(destinationFile, 'wb') as file: for chunk in r: file.write(chunk) print(f"Result file saved as \"{destinationFile}\" file.") else: print(f"Request error: {response.status_code} {response.reason}") else: # Show service reported error print(json["message"]) else: print(f"Request error: {response.status_code} {response.reason}")if __name__ == '__main__': main()
using System;using System.Collections.Generic;using System.IO;using System.Net;using Newtonsoft.Json;using Newtonsoft.Json.Linq;namespace PDFCOWebApiExample{ class Program { // The authentication key (API Key). // Get your own by registering at https://app.pdf.co const String API_KEY = "***********************************"; // Result file name const string ResultFileName = @".\barcode.png"; // Barcode type. See valid barcode types in the documentation https://developer.pdf.co const string BarcodeType = "Code128"; // Barcode value const string BarcodeValue = "qweasd123456"; static void Main(string[] args) { // Create standard .NET web client instance WebClient webClient = new WebClient(); // Set API Key webClient.Headers.Add("x-api-key", API_KEY); // Prepare requests params as JSON // See documentation: https://apidocs.pdf.co/#barcode-generator Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("name", Path.GetFileName(ResultFileName)); parameters.Add("type", BarcodeType); parameters.Add("value", BarcodeValue); // Convert dictionary of params to JSON string jsonPayload = JsonConvert.SerializeObject(parameters); try { // URL of "Barcode Generator" endpoint string url = "https://api.pdf.co/v1/barcode/generate"; // Execute POST request with JSON payload string response = webClient.UploadString(url, jsonPayload); // Parse JSON response JObject json = JObject.Parse(response); if (json["error"].ToObject<bool>() == false) { // Get URL of generated barcode image file string resultFileURI = json["url"].ToString(); // Download generated image file webClient.DownloadFile(resultFileURI, ResultFileName); Console.WriteLine("Generated barcode saved to \"{0}\" file.", ResultFileName); } else { Console.WriteLine(json["message"].ToString()); } } catch (WebException e) { Console.WriteLine(e.ToString()); } finally { webClient.Dispose(); } Console.WriteLine(); Console.WriteLine("Press any key..."); Console.ReadKey(); } }}
package com.company;import com.google.gson.JsonObject;import com.google.gson.JsonParser;import okhttp3.*;import java.io.*;import java.net.*;import java.nio.file.Path;import java.nio.file.Paths;public class Main{ // The authentication key (API Key). // Get your own by registering at https://app.pdf.co final static String API_KEY = "***********************************"; // Result file name final static Path ResultFile = Paths.get(".\\barcode.png"); // Barcode type. See valid barcode types in the documentation https://developer.pdf.co final static String BarcodeType = "Code128"; // Barcode value final static String BarcodeValue = "qweasd123456"; public static void main(String[] args) throws IOException { // Create HTTP client instance OkHttpClient webClient = new OkHttpClient(); // Prepare URL for `Barcode Generator` API call String query = "https://api.pdf.co/v1/barcode/generate"; // Make correctly escaped (encoded) URL URL url = null; try { url = new URI(null, query, null).toURL(); } catch (URISyntaxException e) { e.printStackTrace(); } // Create JSON payload String jsonPayload = String.format("{\"name\": \"%s\", \"type\": \"%s\", \"value\": \"%s\"}", ResultFile.getFileName(), BarcodeType, BarcodeValue); // Prepare request body RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonPayload); // Prepare request Request request = new Request.Builder() .url(url) .addHeader("x-api-key", API_KEY) // (!) Set API Key .addHeader("Content-Type", "application/json") .post(body) .build(); // Execute request Response response = webClient.newCall(request).execute(); if (response.code() == 200) { // Parse JSON response JsonObject json = new JsonParser().parse(response.body().string()).getAsJsonObject(); boolean error = json.get("error").getAsBoolean(); if (!error) { // Get URL of generated barcode image file String resultFileUrl = json.get("url").getAsString(); // Download the image file downloadFile(webClient, resultFileUrl, ResultFile); System.out.printf("Generated barcode saved to \"%s\" file.", ResultFile.toString()); } else { // Display service reported error System.out.println(json.get("message").getAsString()); } } else { // Display request error System.out.println(response.code() + " " + response.message()); } } public static void downloadFile(OkHttpClient webClient, String url, Path destinationFile) throws IOException { // Prepare request Request request = new Request.Builder() .url(url) .build(); // Execute request Response response = webClient.newCall(request).execute(); byte[] fileBytes = response.body().bytes(); // Save downloaded bytes to file OutputStream output = new FileOutputStream(destinationFile.toFile()); output.write(fileBytes); output.flush(); output.close(); response.close(); }}