Pdf - PdfGs1Code128Barcode

18 Nov 20267 minutes to read

Represents a GS1-128 barcode.

// Creates a document.
let document: PdfDocument = new PdfDocument();
// Creates a page.
let page: PdfPage = document.addPage();
// Creates a barcode.
let barcode: PdfGs1Code128Barcode = new PdfGs1Code128Barcode('(01)12345678901231(10)ABC123');
// Draws the barcode at the specified point.
barcode.draw(page, { x: 20, y: 20 });
// Saves the document.
document.save('output.pdf');
// Destroys the document.
document.destroy();

Properties

barHeight number

Gets or sets the bar height in points. The default value is 0, which enables automatic height calculation.

// Creates a document.
let document: PdfDocument = new PdfDocument();
// Creates a page.
let page: PdfPage = document.addPage();
// Creates a barcode.
let barcode: PdfCode39Barcode = new PdfCode39Barcode('CODE39');
// Sets the barHeight.
barcode.barHeight = 60;
// Draws the barcode at the specified point.
barcode.draw(page, { x: 20, y: 20 });
// Saves the document.
document.save('output.pdf');
// Destroys the document.
document.destroy();

Defaults to 0 (automatic)

encodeStartStopSymbols boolean

Gets or sets whether applicable start and stop symbols are included in the displayed text. The default value is false.

// Creates a document.
let document: PdfDocument = new PdfDocument();
// Creates a page.
let page: PdfPage = document.addPage();
// Creates a barcode.
let barcode: PdfCode39Barcode = new PdfCode39Barcode('CODE39');
// Sets the encodeStartStopSymbols.
barcode.encodeStartStopSymbols = true;
// Draws the barcode at the specified point.
barcode.draw(page, { x: 20, y: 20 });
// Saves the document.
document.save('output.pdf');
// Destroys the document.
document.destroy();

Defaults to false

font PdfFont

Gets or sets the font used for human-readable barcode text. The default value is the internal barcode text font.

// Creates a document.
let document: PdfDocument = new PdfDocument();
// Creates a page.
let page: PdfPage = document.addPage();
// Creates a barcode.
let barcode: PdfCode39Barcode = new PdfCode39Barcode('CODE39');
// Sets the font.
barcode.font = new PdfStandardFont(PdfFontFamily.helvetica, 10);
// Draws the barcode at the specified point.
barcode.draw(page, { x: 20, y: 20 });
// Saves the document.
document.save('output.pdf');
// Destroys the document.
document.destroy();

Defaults to Helvetica 8 (PdfStandardFont)

narrowBarWidth number

Gets or sets the width, in points, of the narrowest bar. The default value is 1.

// Creates a document.
let document: PdfDocument = new PdfDocument();
// Creates a page.
let page: PdfPage = document.addPage();
// Creates a barcode.
let barcode: PdfCode39Barcode = new PdfCode39Barcode('CODE39');
// Sets the narrowBarWidth.
barcode.narrowBarWidth = 1.5;
// Draws the barcode at the specified point.
barcode.draw(page, { x: 20, y: 20 });
// Saves the document.
document.save('output.pdf');
// Destroys the document.
document.destroy();

Defaults to 1

text string

Gets or sets the barcode payload text. The default value is an empty string.

// Creates a document.
let document: PdfDocument = new PdfDocument();
// Creates a page.
let page: PdfPage = document.addPage();
// Creates a barcode.
let barcode: PdfCode39Barcode = new PdfCode39Barcode('ABC');
// Sets the text.
barcode.text = 'ABC-123';
// Draws the barcode at the specified point.
barcode.draw(page, { x: 20, y: 20 });
// Saves the document.
document.save('output.pdf');
// Destroys the document.
document.destroy();

Defaults to ’’

textAlignment PdfBarcodeTextAlignment

Gets or sets the horizontal alignment of human-readable text. The default value is Center.

// Creates a document.
let document: PdfDocument = new PdfDocument();
// Creates a page.
let page: PdfPage = document.addPage();
// Creates a barcode.
let barcode: PdfCode39Barcode = new PdfCode39Barcode('CODE39');
// Sets the textAlignment.
barcode.textAlignment = PdfBarcodeTextAlignment.Left;
// Draws the barcode at the specified point.
barcode.draw(page, { x: 20, y: 20 });
// Saves the document.
document.save('output.pdf');
// Destroys the document.
document.destroy();

Defaults to PdfBarcodeTextAlignment.Center

textGap number

Gets or sets the gap, in points, between the bars and human-readable text. The default value is 5.

// Creates a document.
let document: PdfDocument = new PdfDocument();
// Creates a page.
let page: PdfPage = document.addPage();
// Creates a barcode.
let barcode: PdfCode39Barcode = new PdfCode39Barcode('CODE39');
// Sets the textGap.
barcode.textGap = 8;
// Draws the barcode at the specified point.
barcode.draw(page, { x: 20, y: 20 });
// Saves the document.
document.save('output.pdf');
// Destroys the document.
document.destroy();

Defaults to 5

textLocation PdfBarcodeTextLocation

Gets or sets the location of human-readable text. The default value is Bottom.

// Creates a document.
let document: PdfDocument = new PdfDocument();
// Creates a page.
let page: PdfPage = document.addPage();
// Creates a barcode.
let barcode: PdfCode39Barcode = new PdfCode39Barcode('CODE39');
// Sets the textLocation.
barcode.textLocation = PdfBarcodeTextLocation.Top;
// Draws the barcode at the specified point.
barcode.draw(page, { x: 20, y: 20 });
// Saves the document.
document.save('output.pdf');
// Destroys the document.
document.destroy();

Defaults to PdfBarcodeTextLocation.Bottom

Methods

draw

Draws the barcode on a PdfPage or PdfGraphics at the specified point or bounds.
A point or zero-sized bounds use the natural size. Positive bounds scale the barcode to fit the specified size and ignore
narrowBarWidth and barHeight.

Throws if only one of width or height is 0.

// Creates a document.
let document: PdfDocument = new PdfDocument();
// Creates a page.
let page: PdfPage = document.addPage();
// Creates a barcode.
let barcode: PdfGs1Code128Barcode = new PdfGs1Code128Barcode('(01)12345678901231(10)ABC123');
// Draws the barcode at the specified point.
let natural: Rectangle = barcode.draw(page, { x: 20, y: 20 });
// Draws the barcode within the specified bounds.
barcode.draw(page.graphics, { x: 20, y: natural.y + natural.height + 20, width: 250, height: 100 });
// Saves the document.
document.save('output.pdf');
// Destroys the document.
document.destroy();
Parameter Type Description
target PdfPage | PdfGraphics The page or graphics context to draw on.
locationOrBounds Point | Rectangle The point or bounds to draw at. A point or bounds with width and height 0 select the natural size.

Returns Rectangle