Pdf - PdfDataMatrixBarcode
18 Nov 20268 minutes to read
Represents a Data Matrix ECC 200 barcode that can be drawn onto a PDF page or graphics.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Create and configure the barcode
let barcode: PdfDataMatrixBarcode = new PdfDataMatrixBarcode('Test');
barcode.xDimension = 5;
// Draw the barcode on the page
barcode.draw(page, {x: 10, y: 10, width: 100, height: 100});
// Save the document
document.save('output.pdf');
// Destroy the document and release its resources
document.destroy();Properties
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 ’’
xDimension number
Gets or sets the width of one barcode module. The default value is 1.
Get actualColumns number
Gets the column count of the most recently encoded symbol.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Draw and read the encoded symbol dimensions
let barcode: PdfDataMatrixBarcode = new PdfDataMatrixBarcode('Test');
barcode.draw(page, {x: 10, y: 10, width: 100, height: 100});
console.log(barcode.actualColumns); // for example 12
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Get actualRows number
Gets the row count of the most recently encoded symbol.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Draw and read the encoded symbol dimensions
let barcode: PdfDataMatrixBarcode = new PdfDataMatrixBarcode('Test');
barcode.draw(page, {x: 10, y: 10, width: 100, height: 100});
console.log(barcode.actualRows); // for example 12
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Get encoding PdfDataMatrixEncoding
Gets the requested Data Matrix encodation.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Read the configured encodation
let barcode: PdfDataMatrixBarcode = new PdfDataMatrixBarcode('Test');
console.log(barcode.encoding); // PdfDataMatrixEncoding.Auto
barcode.draw(page, {x: 10, y: 10, width: 100, height: 100});
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Set encoding void
Sets the requested Data Matrix encodation.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Configure numeric-only encodation for a digit payload
let barcode: PdfDataMatrixBarcode = new PdfDataMatrixBarcode('001234567890');
barcode.encoding = PdfDataMatrixEncoding.AsciiNumeric;
barcode.draw(page, {x: 10, y: 10, width: 100, height: 100});
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| value | PdfDataMatrixEncoding |
The encodation to apply. |
Get symbolSize PdfDataMatrixSize
Gets the requested symbol size.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Read the configured symbol size
let barcode: PdfDataMatrixBarcode = new PdfDataMatrixBarcode('Test');
console.log(barcode.symbolSize); // PdfDataMatrixSize.Auto
barcode.draw(page, {x: 10, y: 10, width: 100, height: 100});
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Set symbolSize void
Sets the requested symbol size.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Draw the payload in a fixed 20 x 20 symbol
let barcode: PdfDataMatrixBarcode = new PdfDataMatrixBarcode('ITEM-2026-0001');
barcode.symbolSize = PdfDataMatrixSize.Size20x20;
barcode.draw(page, { x: 50, y: 50, width: 32, height: 32 });
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| value | PdfDataMatrixSize |
The symbol size to apply. |
Get textEncoding PdfBarcodeTextEncoding
Gets the requested string-to-byte conversion.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Read the configured text conversion
let barcode: PdfDataMatrixBarcode = new PdfDataMatrixBarcode('Test');
console.log(barcode.textEncoding); // PdfBarcodeTextEncoding.Utf8
barcode.draw(page, {x: 10, y: 10, width: 100, height: 100});
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Set textEncoding void
Sets the requested string-to-byte conversion.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Use ISO-8859-1 conversion for the payload
let barcode: PdfDataMatrixBarcode = new PdfDataMatrixBarcode('Test');
barcode.textEncoding = PdfBarcodeTextEncoding.Iso88591;
barcode.draw(page, { x: 40, y: 40, width: 32, height: 32 });
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| value | PdfBarcodeTextEncoding |
The conversion to apply. |
Methods
draw
Draws the barcode within the supplied bounds and returns the occupied bounds.
Throws an error if the bounds are too small for the required quiet zone.
| Parameter | Type | Description |
|---|---|---|
| target |
PdfPage | PdfGraphics
|
The PDF page or graphics context to draw on. |
| bounds | Rectangle |
The drawing bounds for the barcode. |
Returns Rectangle