This tutorial shows how to read barcode values from a PDF using PDF.co’s Barcode Reader API.
Step 1: Open the Documentation and Code Sample
Open the Barcode Reader documentation and find the Code Samples section. Select JavaScript/Node.js.
The endpoint is:
POST https://api.pdf.co/v1/barcode/read/from/urlSave the Node.js sample as app.js and install any dependencies listed in the sample.
Step 2: Configure the Request
Provide your PDF.co API key from the PDF.co dashboard using the x-api-key request header.
Configure the request body with:
- url: A direct, accessible URL to the PDF or image.
- types: A comma-separated list of barcode types to read, such as
Code128,QRCode. - pages: The pages to scan. Page numbering starts at
0; omit this parameter to scan all pages. - async: Use
falsefor this introductory example.
For example:
{
"url": "https://example.com/barcodes.pdf",
"types": "Code128,QRCode",
"pages": "0",
"async": false
}Replace the example URL with your source file’s URL. Consult the documentation for the complete list of supported barcode types.
Step 3: Run the Sample
Open a terminal in the folder containing app.js and run:
node app.jsThe program sends the request and reads the JSON response.
Step 4: Review the Detected Barcodes
When error is false, inspect the barcodes array. Each detected barcode includes information such as:
TypeName: Barcode formatValue: Decoded contentPage: Page indexRect: Position in the documentConfidence: Recognition confidence
Compare the returned values with the source document. You can then use those values in your application to identify documents, organize records, or route files.
Related Tutorials
