How Judicial Backend generates PDF documents using pdfmake, with shared builders, Roboto font loading, style definitions, and the endpoints that return PDF buffers.
Use this file to discover all available pages before exploring further.
The Judicial Backend generates court-ready PDF documents using pdfmake. All PDF infrastructure lives in src/shared/pdf/ and is consumed by module-level report classes that extend PdfBuilder<T>. The shared layer handles font loading, page layout, institutional headers and footers, and the full pdfmake document definition — module reports only implement construirContenido() to describe the document body specific to their data.
PdfPrinter
src/shared/pdf/pdf.printer.ts — class that loads the Roboto font family from public/fonts/ at module load time and exposes a single imprimir() method.
PdfBuilder
src/shared/pdf/pdf.builder.ts — abstract class that assembles the full TDocumentDefinitions object: page size, margins, institutional header, footer with pagination, and merged styles.
pdf.helpers
src/shared/pdf/pdf.helpers.ts — utility functions for formatting values and constructing typed TableCell objects used throughout report tables.
pdf.styles
src/shared/pdf/pdf.styles.ts — global pdfmake StyleDictionary and the COLORES palette consumed by helpers and builder styles.
The following Roboto variants are present in public/fonts/:
File
pdfmake key
Roboto-Regular.ttf
normal
Roboto-Medium.ttf
bold
Roboto-Italic.ttf
italics
Roboto-MediumItalic.ttf
bolditalics
Roboto-Black.ttf
— (available, not mapped)
Roboto-BlackItalic.ttf
—
Roboto-Bold.ttf
—
Roboto-BoldItalic.ttf
—
Roboto-Light.ttf
—
Roboto-LightItalic.ttf
—
Roboto-Thin.ttf
—
Roboto-ThinItalic.ttf
—
pdfmake requires exactly the four keys normal, bold, italics, and bolditalics. The extra Roboto variants are available on disk and can be added to the fuentes map if a future report needs Black or Light weights.
PdfBuilder.generarDefinicion() merges estilosBase with any caller-supplied estilos via OpcionesDocumento.estilos, so module reports can extend or override styles without touching the shared file.
PdfBuilder<TDato> is the abstract base for all PDF reports. It builds the complete TDocumentDefinitions object and delegates only the body content to subclasses.
Located at src/modules/busqueda/reports/pdf/apelacion-pdf.report.ts.
export class ApelacionPdfReport extends PdfBuilder<ApelacionDTO> { constructor() { super({ titulo: 'REPORTE DE APELACIONES' }); } protected construirContenido(apelaciones: ApelacionDTO[]): Content[]}
The report groups apelaciones by sala. Each sala produces a section label (etiquetaSeccion) followed by a table built with construirTablaSala(). The second and subsequent salas are preceded by pageBreak: 'before'.The main table uses 13 columns (ANCHOS_COLS = [45, 35, 35, 45, 40, 35, 45, 45, 40, 28, 60, 35, 40]) and renders three row types:
Row type
Method
Contents
Header row
filaEncabezado()
13 celdaEncabezado() cells
Data row
filaDatos(apelacion)
13 celdaDato() cells
Nested row
filaAnidada(apelacion)
Cols 1–4 blank, col 5 spans 9 and contains sub-tables
The nested row embeds up to two inner tables using layoutAnidado:
Partes table (widths [60, 118, 70, 41, 41]): Parte, Nombre, Dirección, Menor de Edad, Sexo
Anexos table (widths [60, 118, 70, 90]): Cantidad, Anexo, Es Valor, Monto
Both sub-tables use celdaSubEncabezado() for their header rows.
PdfBuilder and PdfPrinter are intentionally separate. PdfBuilder knows what the document looks like; PdfPrinter only knows how to render it. This lets you unit-test generarDefinicion() by inspecting the returned object without triggering font loading or PDF serialization.
If a logo file is missing from public/assets/, the header gracefully falls back to a plain text placeholder ([LOGO] or [CJO]). This means the server will start and generate valid PDFs even in environments where the asset files have not been deployed yet.