Read Barcodes

Reads barcode and decrypts data.

Code Samples

Try the API in the language you prefer

  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
// create readbarcodes object
var req = new ReadBarcodes()
    {
        // document
        Document = new Document()
        {
            DocData = File.ReadAllBytes("myPdf.pdf")
        },
        // action
        ReadBarcodeAction = new ReadBarcodeAction()
        {
        },
    };
    
// reading barcode from PDF
var res = Pdf4me.Instance.PdfAClient.ProtectAsync(req).GetAwaiter().GetResult();
            
// extracting the text and writing it to disk
string barcodeString = res.Barcodes.FirstOrDefault().BarcodeData;
File.WriteAllBytes("barcodeString.txt", barcodeString);
# setup the barcode_client
barcode_client = BarcodeClient(pdf4me_client)

# create the barcode object
read_barcodes = ReadBarcodes(
    # document
    document=Document(
        doc_data=FileReader().get_file_data('mypdf.pdf')
    ),
    # action
    read_barcode_action=ReadBarcodeAction(
    )
)

# reading barcode from PDF
res = barcode_client.read_barcodes(read_barcodes=read_barcodes)

# extract the text and writing it to disk
barcode_text = base64.b64decode(res['barcodes'][0]['barcode_data'])
with open('barcodeString.txt', 'wb') as f:
    f.write(barcode_text)
 // create readbarcodes object
 $create_barcode = [
    // document
    "document"=> [
        "name"=> "myPdf.pdf",
        "docData" => $pdf4meclient->getFileData('myPdf.pdf')
    ],
    // action
    "readBarcodesAction" => [
    ]
];

// create the barcode object
$res = $client->pdf4me()->readBarcodes($create_barcode);

// extracting the barcode text
$barcode_text = base64_decode($res->barcodes[0]->barcodeData);
// and writing it to file
file_put_contents('barcodeString.txt', $barcode_text);

Important Links

Swagger - Read Barcodes