Pdf Component - PdfBarcode
18 Nov 20262 minutes to read
Abstract base class that provides the common payload, color, quiet-zone, and drawing contract for supported barcodes.
It cannot be instantiated directly; create one of the concrete barcode classes (for example PdfCode39Barcode, PdfEan13Barcode)
and use the shared text, foreColor, backColor and quietZone members and the draw method inherited from this class.
// 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');
// 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
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 ’’
Methods
draw
Draws the barcode within the supplied bounds and returns the occupied rectangle.
// 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');
// 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 | Rectangle |
The drawing bounds. Width and height 0 select the natural size; otherwise both must be positive. |
Returns Rectangle