Skip to main content

Document Renderer - Quick Start

Generate PDFs from text inputs; Markdown and HTML are converted to plain text.

Complete Data Isolation

Primus Document Renderer runs entirely within your application. All document generation happens locally.

Providers

The Document Renderer uses a local generation engine.

Provider 1: Local Renderer

Step 1: Install Package

dotnet add package PrimusSaaS.Documents

Step 2: Configure in Program.cs

using Primus.Documents;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddPrimusDocumentRenderer(opts =>
builder.Configuration.GetSection("PrimusDocuments").Bind(opts));

var app = builder.Build();
app.MapControllers();
app.Run();

Step 3: Configure appsettings.json

{
"PrimusDocuments": {
"Provider": "Default",
"MaxContentLength": 20000,
"BrandName": "Your Company",
"IncludeTimestampInFooter": true,
"IncludeTenantInFooter": true
}
}
How to Configure Values
  • BrandName: Company name shown in PDF footer
  • MaxContentLength: Max characters allowed for input text

Step 4: Create Controller

Create Controllers/DocumentController.cs:

using Microsoft.AspNetCore.Mvc;
using Primus.Documents;

namespace YourApp.Controllers;

[ApiController]
[Route("api/[controller]")]
public class DocumentController : ControllerBase
{
private readonly IDocumentRenderer _renderer;

public DocumentController(IDocumentRenderer renderer)
{
_renderer = renderer;
}

[HttpPost("generate")]
public async Task<IActionResult> GeneratePdf([FromBody] GenerateRequest request)
{
var docRequest = new RenderDocumentRequest
{
TenantId = "default",
Title = request.Title,
ContentType = DocumentContentType.Markdown,
Content = request.Content
};

var pdfBytes = await _renderer.RenderPdfAsync(docRequest);
return File(pdfBytes, "application/pdf", "document.pdf");
}
}

public record GenerateRequest(string Title, string Content);

Step 5: Test Endpoints

curl -X POST http://localhost:5000/api/document/generate \
-H "Content-Type: application/json" \
-d '{"title": "Report", "content": "# Monthly Report\n\n- Sales: $10k"}' \
--output report.pdf

Configuration Reference

Document Renderer Options

OptionTypeDefaultDescription
Providerstring"Default"Provider name
BrandNamestring-Text in footer
MaxContentLengthint20000Max character limit
LinkTtlTimeSpan10 minExpiry for temp links

Examples

Example 1: HTML Content

var request = new RenderDocumentRequest
{
Title = "Invoice",
ContentType = DocumentContentType.Html,
Content = "<h1>Invoice #123</h1><p>Total: $500</p>"
};

Troubleshooting

Issue: Font not found

Solution: Ensure host system has standard fonts installed (Arial, Helvetica) if running in Linux/Docker container.