PDF Export
PDF Export
Section titled “PDF Export”Juca generates PDF documents from briefing sessions using jsPDF. The PDF is rendered server-side as a pure function and delivered via a dedicated API endpoint.
How It Works
Section titled “How It Works”The PDF generation pipeline:
- Client requests PDF via
GET /api/export/pdf/[sessionId] - API route authenticates the request and loads the session
generateBriefingPDF(input)processes session blocks into PDF content- PDF returned as binary (
application/pdf)
Implementation
Section titled “Implementation”The generator is a pure function in src/lib/pdf/generator.ts:
function generateBriefingPDF(input: BriefingPDFInput): Uint8Array { const doc = new jsPDF();
// Extract blocks by type const diagnosis = blocks.find(b => b.type === 'diagnosis'); const precedents = blocks.filter(b => b.type === 'precedent'); const riskBalance = blocks.find(b => b.type === 'risk_balance'); const delivery = blocks.find(b => b.type === 'delivery');
// Render sections with manual Y-position tracking let y = 20; // ... render each section, calling checkPage() for overflow // Use doc.splitTextToSize(text, maxWidth) for text wrapping
return new Uint8Array(doc.output('arraybuffer'));}API Endpoint
Section titled “API Endpoint”GET /api/export/pdf/[sessionId]| Parameter | Type | Location | Required |
|---|---|---|---|
sessionId | string | URL path | Yes |
Authentication: Required. Uses auth() from src/lib/auth.
Response: application/pdf binary content.
Future: Briefing-Aware PDF
Section titled “Future: Briefing-Aware PDF”🚧 Planned Feature — The v0.4 PDF (#289) will reflect user selections across all 4 Briefing phases. The PDF structure will adapt based on the delivery mode (Síntese produces a concise summary; Parecer produces a formal opinion layout).
🚧 Planned Feature — DOCX export is planned for v0.5 (#158).