Skip to content

Repository files navigation

PDF Seal Application

An AI-powered web application for applying company seals to PDF documents with intelligent placement suggestions.

Features

  • 🤖 AI-Powered Placement: Uses Azure OpenAI GPT-4.1 vision to analyze documents and suggest optimal seal positions
  • 📄 Universal Document Support: Works with any document type (contracts, invoices, letters, certificates, forms)
  • Live Preview: Real-time PDF preview with seal overlay
  • 🎯 Manual Controls: Fine-tune seal position, size, and page placement
  • 🔒 Secure Access: Password-protected with JWT authentication
  • 📥 Easy Download: Apply seal and download modified PDF instantly

Getting Started

Prerequisites

  • Node.js 20+
  • npm or yarn
  • Azure OpenAI account with GPT-4.1 deployment

Installation

  1. Clone the repository:
git clone <repository-url>
cd pdf-seal-app
  1. Install dependencies:
npm install
  1. Create .env.local file with required variables:
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
AZURE_OPENAI_API_KEY=your-api-key
AZURE_OPENAI_DEPLOYMENT=gpt-4.1
MASTER_PASSWORD=your-password
JWT_SECRET=your-jwt-secret
  1. Run the development server:
npm run dev
  1. Open http://localhost:3000 in your browser

Build for Production

npm run build
npm start

How It Works

  1. Upload PDF: Drag and drop or select a PDF document
  2. AI Analysis: Click "AI Suggest Position" to get intelligent placement recommendations
  3. Manual Adjustment: Fine-tune position, size, and page using controls
  4. Preview: See real-time preview of seal placement
  5. Apply & Download: Generate and download the sealed PDF

Technology Stack

  • Framework: Next.js 15 with Turbopack
  • UI: React 19, Tailwind CSS 4, Radix UI
  • PDF Processing: pdf-lib, Puppeteer, react-pdf
  • AI: Azure OpenAI GPT-4.1 Vision
  • Authentication: JWT with jose library
  • Image Processing: Sharp, Canvas

Architecture Highlights

Vision-Based AI Analysis

  • Converts PDF pages to high-resolution images using Puppeteer (headless Chrome)
  • Sends images to GPT-4.1 vision API for intelligent analysis
  • Generalized prompts work with any document type without hardcoded assumptions
  • Returns coordinates, reasoning, and confidence score

Pure npm Solution

  • No system-level dependencies required
  • Puppeteer bundles Chromium browser
  • All processing done with npm packages

High-Quality Output

  • 8x resolution seal rendering for print quality (300 DPI)
  • SVG to PNG conversion with sharp
  • Preserves PDF quality and structure

Development

Commands

npm run dev      # Start development server with Turbopack
npm run build    # Build for production
npm start        # Start production server
npm run lint     # Run ESLint

Project Structure

├── app/
│   ├── api/
│   │   ├── analyze-pdf/    # AI vision analysis endpoint
│   │   ├── apply-seal/     # Seal application endpoint
│   │   └── auth/           # Authentication endpoints
│   ├── login/              # Login page
│   └── page.tsx            # Main application
├── components/
│   ├── Header.tsx          # Top navigation
│   ├── PdfUploader.tsx     # File upload component
│   ├── PdfPreview.tsx      # PDF viewer with seal overlay
│   └── SealEditor.tsx      # Control panel
├── lib/
│   ├── azure-openai.ts     # AI vision integration
│   ├── pdf-to-image.ts     # PDF rendering with Puppeteer
│   ├── pdf-processor.ts    # PDF manipulation
│   └── auth.ts             # JWT authentication
└── types/
    └── index.ts            # TypeScript definitions

Environment Variables

Variable Description Required
AZURE_OPENAI_ENDPOINT Azure OpenAI resource endpoint Yes
AZURE_OPENAI_API_KEY Azure OpenAI API key Yes
AZURE_OPENAI_DEPLOYMENT Deployment name (use gpt-4.1) Yes
MASTER_PASSWORD Application access password Yes
JWT_SECRET Secret for JWT token signing Yes

Security

  • Password-protected access with JWT sessions
  • 24-hour session expiration
  • HTTP-only cookies
  • Secure flag enabled in production
  • Middleware-based route protection

Contributing

Contributions are welcome! Please ensure all changes:

  • Follow existing code style
  • Include appropriate error handling
  • Work with the generalized AI prompt system
  • Maintain PDF coordinate system conventions (origin at bottom-left)

License

This project is private and proprietary.

Support

For issues or questions, please contact the development team.

About

An AI-powered web application for applying company seals to PDF documents with intelligent placement suggestions.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages