A minimal .NET 10 template that demonstrates dynamic PDF generation from strongly-typed Blazor invoice components rendered to HTML and converted to PDF with PuppeteerPagePool.
This project shows how to build a document-generation API where:
- Data is generated (or can be supplied from your own domain/service layer).
- A strongly-typed Blazor component renders the invoice HTML server-side.
- A pooled Chromium page converts that HTML into a print-ready PDF.
- A single API endpoint returns the PDF file.
It is designed as a template foundation for reusable, maintainable document rendering pipelines.
- Dynamic invoice generation using typed models.
- Component-based document templates (header, info panel, item table, totals, message).
- Print/PDF-friendly monochrome layout with responsive behavior.
- Efficient PDF rendering via reusable browser/page pooling.
- Minimal API delivery (
GET /api/invoices/pdf) for immediate integration.
- .NET SDK
10.x - Windows/Linux/macOS environment capable of running Chromium (Puppeteer)
git clone <your-repo-url>
cd Invoice-Pdf-Generator
dotnet restore
dotnet run --project InvoicePdf.WebAPIDefault endpoint:
GET /api/invoices/pdf-> returnsapplication/pdf
Development API docs (Swagger UI):
/swagger(enabled in Development environment)
PDF output is fixed to A4 format for consistent print layout.
Endpoint:
GET /api/invoices/pdf
Runtime pipeline:
- Endpoint receives request (
GET /api/invoices/pdf). - Invoice data factory creates a dynamic invoice model.
- Blazor
HtmlRendererrenders invoice components into HTML. PuppeteerPagePoolloads HTML and prints PDF bytes.- API responds with file download (
application/pdf).
This separation keeps document styling and layout in template components while preserving backend service boundaries.
Use this template to build:
- Billing invoices for SaaS, agencies, professional services
- Quotations and estimates
- Purchase orders
- Credit notes
- Delivery notes
- Subscription renewal notices
- Payroll slips and expense statements
- Branded customer statements per tenant/client
You can add more template components (e.g., receipt, quote, statement) and route each to its own endpoint or parameterized selector.
- Generate customer-ready PDFs on demand from business events.
- Batch export invoices for accounting periods.
- Produce tenant-specific branded documents from one backend.
- Serve PDFs directly to frontend apps, portals, or external integrations.
- Keep templates versioned in source control with deterministic rendering rules.
- Template intentionally renders without a logo block for a cleaner print-first layout.
- Data generation currently uses
Bogusfor template/demo behavior. - Replace the random data factory with your real application data source when integrating into production systems.