AVAILABLE NOW: Spring 2025 Release

Read Barcodes and Convert to Searchable PDF with C++ using Apryse SDK

By Apryse | 2025 Jun 24

Sanity Image
Read time

5 min

Barcodes are a ubiquitous tool for handling data in many industries, and Apryse SDK provides the tools you need to work with them. In this sample code, check out how to read barcodes and convert to searchable PDF for use in other workflows.

Sample C++ Code:

#include <iostream> 

#include <PDF/PDFNet.h> 

#include <PDF/PDFDoc.h> 

#include <PDF/OCRModule.h> 

#include <PDF/OCROptions.h> 

#include <PDF/BarcodeModule.h> 

#include <PDF/BarcodeOptions.h> 

#include <SDF/Obj.h> 

 

using namespace pdftron; 

using namespace std; 

using namespace PDF; 

using namespace SDF; 

 

int main(int argc, char *argv[]) { 

    // Initialize the PDFNet library 

    PDFNet::Initialize("your_license_key"); 

 

    // Add resource search paths for OCR and Barcode modules 

    PDFNet::AddResourceSearchPath("path_to_your_OCR_module"); 

    PDFNet::AddResourceSearchPath("path_to_your_barcode_module"); 

 

    try { 

        // Read barcodes from an input image 

        string input_path = "path_to_input.pdf"; 

        string output_path = "path_to_output.json"; 

        PDFDoc bcDoc(input_path); 

        BarcodeModule::ExtractBarcodes(bcDoc, output_path); 

        cout << "Barcodes extracted and saved to " << output_path << endl; 

 

        // Perform OCR on an input image and convert it to a searchable PDF 

        string ocr_input_image_path = "path_to_input.tif"; 

        string searchable_pdf_path = "path_to_output.pdf"; 

        PDFDoc doc; 

        OCROptions opts; 

        OCRModule::ImageToPDF(doc, ocr_input_image_path, &opts); 

        doc.Save(searchable_pdf_path, SDFDoc::e_linearized, 0); 

        cout << "Searchable PDF created and saved to " << searchable_pdf_path << endl; 

    } catch (const Common::Exception& e) { 

        cerr << "Error: " << e.what() << endl; 

        return 1; 

    } 

 

    return 0; 

} 

Next Steps

Copied to clipboard

For more features and functionality of Apryse barcode recognition, check out the documentation, or contact us with any questions.

Sanity Image

Apryse

Share this post

email
linkedIn
twitter