Pdf Component - PdfQRBarcode
18 Nov 202611 minutes to read
Represents a QR Code Model 2 barcode for drawing on a PDF page or graphics context.
// 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 QR barcode
let barcode: PdfQRBarcode = new PdfQRBarcode('https://www.syncfusion.com');
barcode.errorCorrectionLevel = PdfQRErrorCorrectionLevel.Medium;
barcode.xDimension = 3;
// Draw the barcode on the page
barcode.draw(page, { x: 40, y: 40, width: 150, height: 150 });
// Save the document
document.save('output.pdf');
// Destroy the document and release 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 actualVersion number
Gets the version selected during the most recent successful draw.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Draw and inspect the automatically selected version
let barcode: PdfQRBarcode = new PdfQRBarcode('https://www.syncfusion.com');
barcode.draw(page, { x: 40, y: 40, width: 32, height: 32 });
console.log(barcode.actualVersion);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Get errorCorrectionLevel PdfQRErrorCorrectionLevel
Gets the error correction level of the symbol.
// Read the error correction level of a QR barcode
let barcode: PdfQRBarcode = new PdfQRBarcode('Hello');
console.log(barcode.errorCorrectionLevel); // PdfQRErrorCorrectionLevel.MediumSet errorCorrectionLevel void
Sets the error correction level of the symbol.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Use high error correction
let barcode: PdfQRBarcode = new PdfQRBarcode('https://www.syncfusion.com');
barcode.errorCorrectionLevel = PdfQRErrorCorrectionLevel.High;
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 | PdfQRErrorCorrectionLevel |
One of the PdfQRErrorCorrectionLevel members. |
Get inputMode PdfQRInputMode
Gets the input encoding mode applied to the payload.
// Read the input mode of a QR barcode
let barcode: PdfQRBarcode = new PdfQRBarcode('0123456789');
console.log(barcode.inputMode); // PdfQRInputMode.MixedSet inputMode void
Sets the input encoding mode applied to the payload.
The value must be one of the PdfQRInputMode members; any other value
throws an Error. Forced modes
reject unsupported characters at draw time instead of silently converting
them, so PdfQRInputMode.AlphaNumeric rejects lowercase input.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Force numeric input mode
let barcode: PdfQRBarcode = new PdfQRBarcode('0123456789');
barcode.inputMode = PdfQRInputMode.Numeric;
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 | PdfQRInputMode |
One of the PdfQRInputMode members. |
Get logo PdfQRBarcodeLogo
Gets the optional centered logo.
// 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 QR barcode
let barcode: PdfQRBarcode = new PdfQRBarcode('https://www.syncfusion.com');
let logo: PdfQRBarcodeLogo = barcode.logo;
// Draw the barcode on the page
barcode.draw(page, { x: 40, y: 40, width: 150, height: 150 });
// Save the document
document.save('output.pdf');
// Destroy the document and release resources
document.destroy();Set logo void
Sets the optional centered logo.
The value must be a PdfQRBarcodeLogo object or undefined to remove an
existing logo. Logo placement is validated before any PDF content is
emitted; unsafe coverage throws an Error when strict validation is enabled on the logo.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Create QR barcode with centered logo onto the symbol
let barcode: PdfQRBarcode = new PdfQRBarcode('https://example.com/verify/12345', {
errorCorrectionLevel: PdfQRErrorCorrectionLevel.High,
logo: {
data: pngBytes,
size: {
width: 32,
height: 32
}
}
});
// Draw the barcode on the page
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 | PdfQRBarcodeLogo |
The logo configuration, or undefined to remove the logo. |
Get moduleCount number
Gets the module count of the most recent successful draw.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Draw and inspect the module count
let barcode: PdfQRBarcode = new PdfQRBarcode('https://www.syncfusion.com');
barcode.draw(page, { x: 40, y: 40, width: 32, height: 32 });
console.log(barcode.moduleCount);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Get textEncoding PdfBarcodeTextEncoding
Gets the byte conversion used by byte segments.
// Read the text encoding of a QR barcode
let barcode: PdfQRBarcode = new PdfQRBarcode('Hello');
console.log(barcode.textEncoding); // PdfBarcodeTextEncoding.Utf8Set textEncoding void
Sets the byte conversion used by byte segments.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Encode byte segments as ISO-8859-1
let barcode: PdfQRBarcode = new PdfQRBarcode('https://www.syncfusion.com');
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();// Read the text encoding of a QR barcode
let barcode: PdfQRBarcode = new PdfQRBarcode('Hello');
console.log(barcode.textEncoding); // PdfBarcodeTextEncoding.Utf8| Parameter | Type | Description |
|---|---|---|
| value | PdfBarcodeTextEncoding |
One of the PdfBarcodeTextEncoding members. |
Get version PdfQRVersion
Gets the QR symbol version selection.
// Read the version selection of a QR barcode
let barcode: PdfQRBarcode = new PdfQRBarcode('Hello');
console.log(barcode.version); // PdfQRVersion.AutoSet version void
Sets the QR symbol version selection.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Pin the symbol to version 5
let barcode: PdfQRBarcode = new PdfQRBarcode('INVOICE-2026-000123');
barcode.version = PdfQRVersion.Version05;
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 | PdfQRVersion |
The automatic selection or a fixed version member. |
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.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page to the document
let page: PdfPage = document.addPage();
// Draw the barcode within the supplied bounds
let barcode: PdfQRBarcode = new PdfQRBarcode('https://www.syncfusion.com');
barcode.draw(page, { x: 40, y: 40, width: 150, height: 150 });
// Save the document
document.save('output.pdf');
// Destroy the document and release resources
document.destroy();| 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