Skip to main content

Integration Guide

Generate PDFs from text inputs in 5 minutes.


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
}
}
OptionTypeDescription
BrandNamestringCompany name in footer
MaxContentLengthintMax characters allowed

Step 4: Create Controller

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

[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 Endpoint

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

Next Steps

Want to...See Guide
Advanced configurationAdvanced
Multi-tenancy setupMulti-Tenancy