add/barcode


The add/barcode-endpoint adds one or more barcodes to an existing PDF. The source document can be provided as a URL or as a base64-encoded string. A variety of options control the barcode creation: symbology, size, human readable text etc.

This endpoint is intended for processing of medium sized PDFs with no more than 100 pages or so. As such it is best used for processing of letters, reports, forms, receipt, invoices and similar document types.

NEW: Video tutorial

Endpoint: 'https://api.pdfteam.com/api/add/barcode'
Method: 'POST'
Cost: 1
Params:
{
    job: string;
    user: string;
    key: string;
    test?: boolean;
    inputOptions: InputOptions;
    outputOptions?: OutputOptions;
    overlays?: [OverlayOptions];
}

// job: an arbitrary string to identify this job, see return value
// user: user name, see section 'API Access' in your account
// key: API key, see section 'API Access' in your account
// test: if TRUE, the API call will not consume credits. PDFs created
//       in test mode carry a watermark, default: FALSE

Returns:
{
    endpoint: string;
    job: string;
    credits: number;
    result: string;
}

// endpoint: 'add/barcode'
// job: same as above
// credits: number of credits consumed
// result: permalink to the PDF in S3 or a base64 encoded string


NOTE: "Test" mode is intended to dial in settings and options. Currently there are no hard limits on this feature. However, abusing "Test"-mode may lead to account termination, please see our terms.


with InputOptions:

InputOptions {
  source?: string;
  data: string;
}

// source: must be a fully qualified, publicly accessible URL (fetch timeout: 10sec.)
// data: a base64 encoded string, beginning with or without data URI, e.g.
//       'data:application/pdf;base64,JVBER...'
//
//       or
//
//       'JVBER...'
//
// If both params are given, source has precedence
//
// NOTE: If the source is not accessible or the data string can't be converted, the endpoint
// will return a 400 status code with an error message


with OutputOptions:

OutputOptions {
  storage?: boolean;
  file?: string;
}

// storage: if TRUE, write file to S3, else return PDF as base64, default: TRUE
// file: file name for document in S3, default: random uuid (v4)
//
// NOTE: File name must not contain '/' or ':'


with OverlayOptions:

OverlayOptions {
  type: string;
  position?: {
    x: string;
    y: string;
  };
  firstPageOnly?: Boolean;
  rotate?: number;
  config: BarcodeConfig;
}

// type: "barcode"
// position.*: specify as cm, mm or inches (e.g. "10mm", "0.5in" etc.), default: x=0, y=0
// position.x: specify as "left" | "center" | "right"
// position.y: specify as "top" | "middle" | "bottom"
// firstPageOnly: if TRUE, put barcode on first page only, default: FALSE
// rotate: rotate by degrees, positive values rotate CCW, default: 0


with BarcodeConfig:

NOTE: Section below is only an excerpt of all available configuration options for barcode creation; all other parameters will be at reasonable defaults for most users. For a more thorough treatment see the barcode reference.

BarcodeConfig {
  data: string;
  type?: number;
}

// type: one of the following:
//
//       EAN 8 = 0
//       EAN 13 = 1
//       ISBN 10 = 2
//       ISBN 13 = 3
//       ISSN = 4
//       UPC-A = 5
//       UPC-E = 6
//       Code 128 = 7
//       Code 128 GS1 = 8
//       Code 2/5 Interleaved = 9
//       Code 2/5 Standard = 10
//       ITF-14 = 11
//       Code 39 = 12
//       PZN = 13
//       Laetus = 14
//       Codabar = 15
//       Datamatrix = 16
//       Datamatrix GS1 = 17
//       PDF417 = 18
//       QR = 19
//       Aztec = 20
//
//       default: 19 (QR)
// data: data to be encoded into the barcode. With QR, this will usually be a fully
//       qualified URL, e.g. 'https://pdfteam.com'. For other barcode types see the
//       requirements in the link above.


NOTE: For QR, make sure to also see this page on using QR with structured content


Code sample I (NodeJS with fetch)

Following is a code sample that adds a QR code to a PDF (source):

// Sample code for accessing the PDFTeam API, endpoint: add/barcode

const url = 'https://api.pdfteam.com/api/add/barcode';

let params = {
  job: '00012345',
  user: 'YOUR_USERNAME',
  key: 'YOUR_APIKEY',
  inputOptions: {
    source: 'https://pdfteam.com/samples/invoice.pdf',
  },
  outputOptions: {
    storage: true,
    file: 'barcode_invoice.pdf',
  },
  overlays: [
    {
      position: {
        x: '18mm',
        y: '25mm',
      },
      type: 'barcode',
      config: {
        type: 19,
        data: 'https://pdfteam.com'
      },
    }
  ]
};

fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(params),
}).then((result) => {
  result.text().then((text) => {
    console.log(text);
  });
});


Sample response:

{
  'endpoint':'add/barcode',
  'job':'00012345',
  'credits':1,
  'result':'https://pdfteam.s3.eu-north-1.amazonaws.com/.../barcode_invoice.pdf'
}


Result I:

Adding a QR code to a PDF with NodeJS


Code sample II (NodeJS with fetch)

Multiple barcodes can be created simply by adding more overlays. Here we add a Code 128 (type '7') encoding the job number ('00012345') to the PDF, rotated by 90 degrees and positioned at the middle left:


  ...
  overlays: [
    {
      position: {
        x: '18mm',
        y: '25mm',
      },
      type: 'barcode',
      config: {
        type: 19,
        data: 'https://pdfteam.com'
      },
    },
    {
      rotate: 90,
      position: {
        x: '15mm',
        y: 'middle',
      },
      type: 'barcode',
      config: {
        humanReadableText: false,
        moduleHeight: 10,
        type: 7,
        data: '00012345'
      },
    }
  ]
  ...


Result II:

PDF with QR code and a Code 128 barcode

More code samples


PDF API Endpoint add/barcode sample: Python
PDF API Endpoint add/barcode sample: Rust
PDF API Endpoint add/barcode sample: C#
PDF API Endpoint add/barcode sample: PHP