Cloudflare Workers PDF417 Driver License API

Build an edge API proxy that decodes US driver license PDF417 barcodes and returns normalized AAMVA JSON with safe retake handling.

Designing a Safe PDF417 Route in Cloudflare Workers

A production Cloudflare Workers integration must protect the API key, reject oversized uploads, preserve enough image quality for decoding, and translate recoverable 422 responses into a useful capture experience. A browser-only request would expose credentials and make abuse controls harder.

A Server-Side Cloudflare Workers Integration

A Worker can protect the API key and forward Base64 JSON from an approved application origin while applying request-size and rate limits. The PDF417 API reference documents the complete response and error model. Identity fields are only returned after deterministic barcode decoding and AAMVA parsing.

Where This Workflow Fits

  • Protected upload endpoint: Keep STRUCTOCR_API_KEY inside Cloudflare Workers server configuration rather than client code.
  • Structured form prefill: Map normalized AAMVA fields into an editable form and require user or staff confirmation.
  • Recoverable retake flow: Turn PDF417_NOT_DECODED into a clear request for a sharper, complete license-back image.
Need more testing? Create a free account to get 200 free credits (equals 100 Driver License scans).

Cloudflare Workers PDF417 Endpoint

The example accepts image data on the server and calls /v1/driver-license-pdf417. Adapt authentication, authorization, rate limits, and retention to your application.

Prerequisite: Bind STRUCTOCR_API_KEY as a Worker secret; no SDK package is required for the edge proxy

TYPESCRIPT EXAMPLE
interface Env { STRUCTOCR_API_KEY: string }

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    if (request.method !== "POST") return new Response("Method not allowed", { status: 405 });
    const body = await request.json<{ img?: string }>();
    if (!body.img) return Response.json({ error: "img is required" }, { status: 400 });

    const upstream = await fetch("https://api.structocr.com/v1/driver-license-pdf417", {
      method: "POST",
      headers: { "content-type": "application/json", "x-api-key": env.STRUCTOCR_API_KEY },
      body: JSON.stringify({ img: body.img }),
    });
    return new Response(upstream.body, { status: upstream.status, headers: { "content-type": "application/json" } });
  },
};

Technical Specs

  • •Endpoint: POST https://api.structocr.com/v1/driver-license-pdf417
  • •Authentication: x-api-key kept in server-side configuration
  • •Inputs: JPG, PNG, or WebP; maximum 4.5 MB
  • •Success: Normalized AAMVA JSON with source set to pdf417
  • •Recoverable errors: PDF417_NOT_DECODED and AAMVA_NOT_VALID return HTTP 422
  • •Cost: 2 credits for a successful decode; processing failures are refunded

Key Features

  • •No browser secret: The capture client uploads to your protected backend route.
  • •No AI guessing: Unreadable barcodes fail explicitly instead of producing plausible identity values.
  • •Data minimization: The route can select only the fields required by the calling workflow.
  • •Operational control: Your service owns authorization, logging redaction, retry behavior, and retention.

Cloudflare Workers Response Shape

The example contains fictional identity values. Optional AAMVA elements can be null, and production logs should avoid storing raw identity data.

{
  "success": true,
  "data": {
    "type": "drivers_license",
    "source": "pdf417",
    "country_code": "USA",
    "region": "CA",
    "document_number": "SAMPLE1234",
    "surname": "SAMPLE",
    "given_names": "ALEX MORGAN",
    "first_name": "ALEX",
    "middle_name": "MORGAN",
    "sex": "X",
    "date_of_birth": "1990-01-15",
    "date_of_issue": "2025-01-15",
    "date_of_expiry": "2030-01-15",
    "address": "100 EXAMPLE AVE",
    "city": "SAMPLE CITY",
    "postal_code": "00000",
    "vehicle_class": "C",
    "restrictions": null,
    "endorsements": null,
    "document_discriminator": "SAMPLE-DISCRIMINATOR",
    "issuer_identification_number": null,
    "aamva_version": 10,
    "jurisdiction_version": 0
  }
}

Frequently Asked Questions

Should Cloudflare Workers call the PDF417 API from the browser?

No. Keep the StructOCR API key on the server and expose only an authenticated application route to approved clients.

Should the integration retry a 422 response automatically?

No. A 422 normally requires a clearer or correct document image. Ask the user to retake it rather than resending the same input.

Does the endpoint authenticate a driver license?

No. It decodes and parses the AAMVA barcode record. Authenticity and identity decisions require additional controls.

You May Also Like

Related tutorials, platform guides, and comparisons

Tutorial

Express PDF417 Driver License API

Build an Express multipart endpoint that decodes US driver license PDF417 barcodes and returns normalized AAMVA JSON with safe retake handling.

Driver License
Country Tutorial

Maryland Driver License OCR: Extract Fields with Python

Extract visible fields from Maryland driver license images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.

Python · Driver License
Tutorial

C# / .NET US Driver License PDF417 API Tutorial

Decode US driver license PDF417 barcodes with C# / .NET. Send a license-back image, parse AAMVA fields, and handle unreadable barcode errors safely.

C# · Driver License
Tutorial

Python US Driver License PDF417 API Tutorial

Decode US driver license PDF417 barcodes with Python. Send a license-back image, parse AAMVA fields, and handle unreadable barcode errors safely.

Python · Driver License
Country Tutorial

Kansas Driver License OCR: Extract Fields with Python

Extract visible fields from Kansas driver license images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.

Python · Driver License
Country Tutorial

Australia Driver License OCR with Node.js SDK

Extract structured fields from a Australia state or territory driver licence with the StructOCR Node.js SDK and TypeScript + Express.

Node.js · Driver License
Country Tutorial

Brazil Driver License OCR with Node.js SDK

Extract structured fields from a Brazil Carteira Nacional de Habilitação (CNH) with the StructOCR Node.js SDK and TypeScript + Express.

Node.js · Driver License
Country Tutorial

Brazil Driver License OCR with Python SDK

Extract structured fields from a Brazil Carteira Nacional de Habilitação (CNH) with the StructOCR Python SDK and FastAPI.

Python · Driver License
Country Tutorial

Australia Driver License OCR with Python SDK

Extract structured fields from a Australia state or territory driver licence with the StructOCR Python SDK and FastAPI.

Python · Driver License
Tutorial

Why Cropped Driver License PDF417 Barcodes Fail

Prevent cropped PDF417 failures by preserving barcode quiet zones, complete stacked rows, image orientation, and enough surrounding card context.

Driver License
Tutorial

Java State ID Card PDF417 API Tutorial

Decode US state and Canadian provincial ID card PDF417 barcodes with Java. Parse AAMVA fields and tell ID cards from driver licenses.

Java · Driver License

Technical Comparisons & Integrations

Explore platform integrations and competitive analysis

From tutorial to production in 5 minutes.

You've seen the code. Now get your API key, grab your 200 free credits, and see it work with your own images. No credit card required.

Instant Access Cancel Anytime No Credit Card