RedCard API

FastAPI service that generates print-ready, multilingual “Know Your Rights” red cards—built with full Unicode, RTL, and CJK support, inspired by ILRC advocacy materials.

FastAPIPythonReportLabPDF GenerationInternationalization (i18n)Unicode / RTL / CJKFont Engineering

What are Red Cards?

Red Cards are small, wallet-sized cards that clearly state a person’s constitutional rights—most commonly the right to remain silent and the right to refuse consent to searches.

They are often used during encounters with law enforcement to:

  • communicate rights without escalating a situation
  • overcome language barriers
  • provide clarity under stress

This project is inspired by the Know Your Rights red cards published by the Immigrant Legal Resource Center (ILRC) and similar advocacy organizations. The goal is to make these materials easier to generate, translate, and distribute at scale, while preserving accuracy and readability.


Why this project matters

Most tools that attempt to generate multilingual PDFs fail once you leave basic Latin text.

RedCard API focuses on the hard, real-world constraints:

  • multiple writing systems
  • right-to-left languages
  • dense legal text
  • physical printing requirements

The result is an API that advocacy groups, civic platforms, or community tools could realistically rely on.


What the API does (high-impact features)

🔴 Print-ready rights cards, on demand

  • Generates multi-card PDF sheets (4, 6, 8, or 12 cards per page)
  • Optimized for physical printing and cutting
  • Two-sided layout:
    • Front: translated rights statement
    • Back: English explanation of 4th & 5th Amendment rights

🌍 Real multilingual support (not just translation)

  • Supports 56+ languages across 22 scripts
  • End-to-end Unicode-safe rendering
  • Each language is checked against actual font coverage

🔁 Correct RTL rendering (Arabic / Hebrew)

  • Proper bidirectional text shaping
  • Prevents mirrored glyphs, broken punctuation, and reversed sentences
  • Avoids common PDF “RTL hacks” that fail in production

🈶 Robust CJK wrapping (Chinese / Japanese / Korean)

  • Implements character-level line breaking
  • Prevents overflow where spaces do not exist
  • Maintains readable layouts for dense text blocks

🔤 Script-aware font system

  • Uses Noto Sans font families to maximize glyph coverage
  • Includes a font validation pipeline to detect unsupported scripts
  • API surfaces font support status instead of failing silently

API design highlights

Stateless, embeddable endpoints

Designed to plug into:

  • advocacy websites
  • civic kiosks
  • community distribution tools
  • print workflows

Core endpoints

  • GET /api/render/{code}?cards_per_page=4
    → returns a downloadable, print-ready PDF
  • GET /api/languages
    → lists supported languages + font coverage status
  • GET /api/card/{code}
    → returns translated card content (non-PDF)
  • GET /api/health
    → service status + language count
  • GET /api/config
    → valid layouts and defaults

Internal rendering pipeline

  1. Validate language + layout
  2. Load translated rights text
  3. Select appropriate font family
  4. Compute grid + spacing
  5. Render front sheet (translated text)
  6. Render back sheet (English rights text)
  7. Return a two-page PDF (front + back)

Rendering is in-memory, returning raw PDF bytes—simple to deploy and scale.


Engineering challenges solved

  • PDF engines are not Unicode-safe by default
    → explicit shaping, bidi handling, and font control
  • CJK text breaks naive wrapping algorithms
    → custom character-based line breaking
  • Missing fonts cause silent failures
    → proactive validation + API visibility

Tech stack

  • FastAPI + Uvicorn
  • ReportLab for low-level PDF rendering
  • arabic-reshaper + python-bidi for RTL support
  • Noto Sans font families for broad Unicode coverage