Backend · Tooling

Go PDF Generation Service

Internal document workflow automation for Smart Grid Solutions

GoPDFREST APIDocument Generation

Overview

Built a Go-based PDF generation service for Smart Grid Solutions, powering internal document workflows and automated output generation for operational reports.

Context

The client needed to generate structured PDF reports from operational data on a recurring schedule, as well as on-demand via an internal dashboard. The existing approach involved manual export and formatting in spreadsheet software — slow, inconsistent, and not scalable as report volume grew.

Architecture

The service exposes a REST API that accepts a report specification (template ID + data payload) and returns a PDF. Generation is synchronous for small reports and async with a polling endpoint for large ones.

POST /reports
{
    "template": "operational-summary",
    "data": { ... },
    "format": "pdf"
}

→ 200 { "job_id": "abc123", "status": "pending" }

GET /reports/abc123
→ 200 { "status": "complete", "url": "..." }

Template Engine

Templates are defined in a structured format that separates layout from data. This allowed non-engineers to modify report templates without touching Go code. The engine handles:

  • Multi-page layout with automatic pagination
  • Header/footer with page numbering
  • Tables with dynamic row counts
  • Embedded charts rendered from data series

Reliability

PDF generation can fail in subtle ways — missing fonts, malformed data, memory spikes on large datasets. The service handles each failure mode explicitly:

  • Input validation before any rendering work begins
  • Hard memory limits per generation job
  • Detailed error responses that identify the exact field or template element that failed

Technical Stack

Go · REST API · HTML/CSS templating · wkhtmltopdf · Docker