Barcodes
webPDF supports the recognition and creation of barcodes in various common barcode formats using the Barcode web service.
| HTTP REST-API | OpenAPI |
|---|---|
POST /barcode/{documentId} | 🔗 |
The mode for the barcode service is set with the add (generation) and detect (recognition) parameters. Moreover, the various parameters can be used to configure the way in which the generation or recognition (e.g. search for barcodes on an entire page or a page area) operation will work.
An example of how to add a QR code to a PDF document:
{
"barcode": {
"add": {
"qrcode": [
{
"charset": "utf-8",
"errorCorrection": "l",
"margin": 3,
"pages": "*",
"position": {
"coordinates": "user",
"height": 20,
"metrics": "mm",
"width": 20,
"x": 50,
"y": 100
},
"rotation": 0,
"value": "https://www.webpdf.de"
}
]
}
}
}
An example of barcode recognition on the entire first page for QR and DataMatrix barcodes.
{
"barcode": {
"detect": {
"inputFormat": "pdf",
"outputFormat": "json",
"selection": [
{
"charset": "utf-8",
"formats": "qrcode,datamatrix",
"pages": "1",
"pureBarcode": false,
"resolution": 200,
"scanArea": {
"coordinates": "user",
"height": 90.47,
"metrics": "mm",
"width": 91.32,
"x": 84.1,
"y": 100.93
},
"tryHarder": true
}
]
}
}
}
Recognition mode​
In recognition mode (parameter detect), the web service searches for all selected barcode formats (parameter formats) on the entire page or in a selected area (parameter selection.scanArea) of a PDF document (parameter inputFormat). If a PDF document contains multiple pages, the search can be further limited using the pages parameter.
Limiting the number of pages scanned and the size of the scanned area on those pages can significantly reduce the analysis time required for the recognition process.
Depending on the selected option, the web service will structure the corresponding results in the form of a JSON or XML document (parameter outputFormat).
For 2D barcode formats (e.g. QR or DataMatrix barcodes), the search can also be executed for graphics formats (the inputFormat parameter with JPG, PNG and TIF image formats).
If there are multiple barcodes of the same format on the source document, it is highly advisable to limit the size of the area to be scanned, otherwise the recognition process may fail. In this case, it is recommended to select a separate area for each barcode and recognize these barcodes separately.
For 1D barcodes, it is always recommended to narrow the search area, otherwise they cannot be reliably found.
Creation mode​
In generation mode (parameter add), the web service will generate a barcode in the selected format and place it on as many pages as you want in the passed PDF document. The output document will always be a PDF document.
Supported formats​
webPDF supports various barcode formats, which can be divided into two groups:
- One-dimensional (linear) barcodes (also known as 1D barcodes)
- Two-dimensional barcodes (also known as 2D barcodes)
These two groups of barcodes are divided into the different formats that can be created or recognized using the Barcode web service.
Output formats​
In recognition mode, the Barcode web service offers JSON and XML as output formats for the barcodes found. This output format can be defined with the outputFormat option in the parameters.
The document’s format is described by the http://schema.webpdf.de/1.0/extraction/barcode.xsd schema.
XML​
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<barcodes xmlns="http://schema.webpdf.de/1.0/extraction/barcode">
<barcode type="qrcode" page="61" errorCorrectionLevel="L">
<rectangle coordinates="user" x="407.0" y="73.0" width="43.5" height="44.0"/>
<rectangle coordinates="pdf" x="407.0" y="725.0" width="43.5" height="44.0"/>
<plain>webPDF</plain>
</barcode>
</barcodes>
Every barcode element found in barcodes represents one recognized barcode, with its page and type attributes providing the page and format for it. In addition, there may be additional metainformation after the attributes. This metainformation may contain further information regarding the barcode depending on the specific barcode format involved.
The plain element contains the barcode’s decoded value, while the rectangle elements contain the position of the barcode on the corresponding page.
JSON​
The structure in JSON format corresponds to the contexts of the XML structure.
{
"barcodes": {
"barcode": [
{
"rectangle": [
{
"x": 407.0,
"y": 73.0,
"width": 43.5,
"height": 44.0,
"coordinates": "user"
},
{
"x": 407.0,
"y": 725.0,
"width": 43.5,
"height": 44.0,
"coordinates": "pdf"
}
],
"plain": "webPDF",
"type": "qrcode",
"page": 61,
"errorCorrectionLevel": "L"
}
]
}
}