Skip to content

srivtx/pdf-generation-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ PDF Generation Engine

A blazingly fast, feature-rich PDF generation engine built with modern Node.js

Transform any content into beautiful PDFs with just one command. From simple text to complex JSON structures, this engine handles it all with precision and style.

Node.js License: MIT Docker Render


✨ Why This Engine?

Built from the ground up with developer experience in mind, this isn't just another PDF converter. It's a complete solution that bridges the gap between content and presentation.

🎯 Smart Auto-Detection - Automatically detects content type
⚑ Lightning Fast - Powered by Puppeteer's Chrome engine
🎨 Beautiful Output - Professional styling out of the box
🌐 Web Ready - Full REST API + Interactive web interface
🐳 Deploy Anywhere - Docker-ready for instant deployment

πŸš€ Features That Set Us Apart

Feature Description Status
Multi-Format Support Text, HTML, JSON, Markdown - we've got you covered βœ…
Intelligent JSON Rendering Structured, Table, or Raw display modes βœ…
Web Interface Drag-and-drop file conversion with live preview βœ…
REST API Full-featured API for integration βœ…
CLI Power Command-line interface for automation βœ…
Smart Templates Customizable HTML templates with CSS styling βœ…
Batch Processing Convert multiple files at once βœ…
Docker Ready One-command deployment anywhere βœ…
Auto-Detection Automatically detects input format βœ…
Production Ready Built for scale with proper error handling βœ…

πŸ“‹ Supported Input Formats

πŸ“„ Plain Text

Perfect for documentation, notes, and simple content.

Simple text content that gets converted to a clean PDF format.
Multi-line support with automatic formatting.

🌐 HTML

Full HTML support with CSS styling and complex layouts.

<h1>Rich Content</h1>
<p>Complete HTML support with <strong>styling</strong></p>
<table>
  <tr><td>Tables</td><td>βœ… Supported</td></tr>
</table>

πŸ“Š JSON (3 Display Modes!)

  • Structured: Clean, hierarchical view
  • Table: Automatic table generation for arrays
  • Raw: Pretty-printed JSON with syntax highlighting
{
  "title": "Smart JSON Rendering",
  "features": ["Auto-formatting", "Multiple views", "Syntax highlighting"],
  "data": [
    {"name": "Alice", "role": "Developer"},
    {"name": "Bob", "role": "Designer"}
  ]
}

πŸ“ Markdown

Full CommonMark support with extensions.

# Professional Documents
## With **rich** formatting
- Lists and tables
- Code blocks with syntax highlighting
- Links and images
> Blockquotes and more!

⚑ Quick Start

Installation

# Clone this masterpiece
git clone https://github.com/your-username/pdf-generation-engine.git
cd pdf-generation-engine

# Install dependencies
npm install

# Ready to rock! 🎸

πŸš€ Instant Usage

# Convert any file instantly
npm start -- --input document.md --output beautiful.pdf --type markdown

# Convert text on the fly
npm start -- --text "Transform this!" --output magic.pdf --type text

# Launch the web interface
npm start -- --server
# Visit http://localhost:3000 for the interactive interface

πŸ’» Usage Examples

πŸ–₯️ Command Line Interface (CLI)

# Basic conversion
npm start -- --input README.md --output docs.pdf --type markdown

# Advanced options with JSON formatting
npm start -- --input data.json --output report.pdf --type json --format table

# Custom PDF settings
npm start -- --input content.html --output styled.pdf --type html --format A4

# Batch processing
npm start -- --input "*.md" --output batch/ --type markdown

🌐 Web Interface

The interactive web interface provides:

  • πŸ“ Drag & Drop file upload
  • πŸŽ›οΈ Live format selection (JSON: Structured/Table/Raw)
  • πŸ‘€ Instant preview before conversion
  • ⬇️ One-click download

Start the server and visit http://localhost:3000:

npm start -- --server

πŸ”Œ REST API Integration

Our RESTful API is perfect for integrating into your applications:

Convert Content Directly

const response = await fetch('http://localhost:3000/api/convert', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    content: '# Hello World\nThis is **markdown**!',
    type: 'markdown',
    options: {
      filename: 'awesome.pdf',
      format: 'A4'
    }
  })
});

const pdfBlob = await response.blob();

Upload & Convert Files

const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('type', 'auto'); // Auto-detect format
formData.append('jsonFormat', 'table'); // For JSON files

const response = await fetch('http://localhost:3000/api/upload', {
  method: 'POST',
  body: formData
});

βš™οΈ Advanced Configuration

Customize every aspect of your PDF generation with config.json:

{
  "pdf": {
    "format": "A4",           // A4, A3, A5, Legal, Letter, Tabloid
    "margin": {
      "top": "1cm",
      "right": "1cm", 
      "bottom": "1cm",
      "left": "1cm"
    },
    "printBackground": true,   // Include CSS backgrounds
    "preferCSSPageSize": true, // Respect CSS page sizes
    "displayHeaderFooter": false,
    "headerTemplate": "",
    "footerTemplate": ""
  },
  "server": {
    "port": 3000,
    "host": "0.0.0.0"         // Bind to all interfaces
  },
  "templates": {
    "default": "default.html", // Custom template path
    "style": {
      "theme": "professional", // professional, minimal, modern
      "fontFamily": "Arial, sans-serif",
      "fontSize": "12pt"
    }
  }
}

🎨 Custom Templates

Create your own HTML templates in src/templates/:

<!DOCTYPE html>
<html>
<head>
    <style>
        body { font-family: 'Helvetica Neue', sans-serif; }
        .header { border-bottom: 2px solid #007acc; }
        .content { margin: 20px 0; }
    </style>
</head>
<body>
    <div class="header">{{title}}</div>
    <div class="content">{{content}}</div>
</body>
</html>

πŸ—οΈ Architecture & Project Structure

Built with modern Node.js and ES modules for maximum performance and maintainability.

πŸ“¦ PDF Generation Engine
β”œβ”€β”€ πŸš€ src/
β”‚   β”œβ”€β”€ πŸ“„ index.js                 # Main application entry point
β”‚   β”œβ”€β”€ πŸ”„ converters/              # Format-specific converters
β”‚   β”‚   β”œβ”€β”€ textConverter.js        # Plain text β†’ HTML
β”‚   β”‚   β”œβ”€β”€ htmlConverter.js        # HTML processing & validation
β”‚   β”‚   β”œβ”€β”€ jsonConverter.js        # JSON β†’ Formatted display
β”‚   β”‚   └── markdownConverter.js    # Markdown β†’ HTML (CommonMark)
β”‚   β”œβ”€β”€ ⚑ generators/              # PDF generation engine
β”‚   β”‚   └── pdfGenerator.js         # Puppeteer-powered PDF creation
β”‚   β”œβ”€β”€ 🌐 server/                  # Web server & API
β”‚   β”‚   β”œβ”€β”€ app.js                  # Express server with REST API
β”‚   β”‚   └── public/                 # Web interface assets
β”‚   β”œβ”€β”€ πŸ› οΈ  utils/                   # Utility functions
β”‚   β”‚   └── helpers.js              # Config, validation, file operations
β”‚   └── 🎨 templates/               # HTML templates
β”‚       └── default.html            # Professional default template
β”œβ”€β”€ πŸ“š examples/                    # Sample files for testing
β”œβ”€β”€ πŸ“‹ output/                      # Generated PDF files
β”œβ”€β”€ 🐳 Dockerfile                   # Production deployment
β”œβ”€β”€ βš™οΈ  config.json                 # Configuration file
└── πŸ“– README.md                    # This beautiful documentation

🧩 Core Components

  • πŸ”§ Converters: Modular design for easy extension
  • ⚑ PDF Generator: Puppeteer-based with Chrome rendering
  • 🌐 Web Server: Express.js with CORS and file upload
  • πŸ› οΈ Utilities: Smart content detection and validation
  • 🎨 Templates: Customizable HTML/CSS for beautiful output

🎯 Example Gallery

Explore our examples/ directory for ready-to-use sample files:

πŸ“„ example.txt

Clean, professional text formatting with automatic line breaks
and paragraph spacing. Perfect for documentation and reports.

🌐 example.html

Rich HTML with tables, lists, and styling that renders beautifully in PDF format.

πŸ“Š example.json

{
  "title": "Smart JSON Display",
  "users": [
    {"name": "Alice", "role": "Developer", "experience": "5 years"},
    {"name": "Bob", "role": "Designer", "experience": "3 years"}
  ]
}

Renders as beautiful tables when using --format table

πŸ“ example.md

---
title: Professional Markdown
author: Your Name
---

# Full CommonMark Support
## With syntax highlighting, tables, and more!

| Feature | Status |
|---------|--------|
| Headers | βœ… |
| Tables  | βœ… |
| Code    | βœ… |

πŸš€ Deployment Options

🐳 Docker Deployment

# Build the image
docker build -t pdf-engine .

# Run locally
docker run -p 3000:3000 pdf-engine

# Deploy to any cloud platform

☁️ Cloud Deployment (Render - Recommended)

  1. Push to GitHub
  2. Connect to Render
  3. Deploy automatically with our Dockerfile
  4. Get a live URL instantly!

Why Render?

  • βœ… Free 750 hours/month
  • βœ… Perfect Puppeteer support
  • βœ… Auto-deploys from Git
  • βœ… HTTPS by default

πŸŽ–οΈ Built With Pride

This engine represents hours of careful engineering, optimization, and attention to detail. Every component is designed for:

  • πŸš€ Performance - Lightning-fast PDF generation
  • πŸ”’ Reliability - Production-ready error handling
  • 🎨 Quality - Beautiful, professional output
  • πŸ”§ Extensibility - Easy to customize and extend

πŸ“œ License

MIT License - Feel free to use this in your own projects!


⭐ Star this repo if it helped you create amazing PDFs! ⭐

Built with ❀️ and lots of β˜•

Releases

No releases published

Packages

No packages published