Skip to main content
GET
/
api
/
reports
/
export
/
pdf
/
table
Export to PDF
curl --request GET \
  --url https://api.example.com/api/reports/export/pdf/table
Exports transaction data to PDF format. Two variants available: Table (fast, optimized) and Visual (styled, rich design).

PDF Variants

Table PDF

Fast tabular format using PDFKit (recommended for large datasets)

Visual PDF

Styled report with charts and branding using Puppeteer

Table PDF (Fast)

Endpoint: GET /api/reports/export/pdf/table Optimized for speed and large transaction volumes. Uses native PDFKit-Table library.

Authentication

Requires Bearer token authentication via Authorization header.

Query Parameters

accountId
string
Filter transactions by a specific account. If omitted, exports all transactions.

Response

  • Content-Type: application/pdf
  • File Name: movimientos_tabla.pdf
  • Format: A4 with 30px margins
  • Max Records: 2,000 transactions

Document Structure

Header Section
  • Title: “Reporte de Movimientos”
  • Generated date
  • Total records count
  • Account filter (if applied)
Table Columns
ColumnWidthAlignmentDescription
Fecha60pxLeftTransaction date (YYYY-MM-DD)
Tipo50pxLeft”Ingreso” or “Gasto”
Categoría80pxLeftCategory name or ”-“
Cuenta80pxLeftAccount name or ”-“
Descripción140pxLeftTransaction description
Monto70pxRightAmount with 2 decimals
Mon30pxLeftCurrency code
Styling
  • Headers: Bold, 8pt font
  • Amount Colors: Green for income, red for expenses
  • Font: Helvetica

Example Request

curl -X GET "https://api.yourfinanceapp.com/api/reports/export/pdf/table?accountId=account_123" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -o transactions.pdf

Visual PDF (Styled)

Endpoint: GET /api/reports/export/pdf/visual Rich, visually appealing report with HTML/CSS styling rendered via Puppeteer.

Authentication

Requires Bearer token authentication via Authorization header.

Query Parameters

accountId
string
Filter transactions by a specific account. If omitted, exports all transactions.

Response

  • Content-Type: application/pdf
  • File Name: reporte_visual.pdf
  • Format: A4 with custom margins (20px sides, 40px bottom)
  • Max Records: 2,000 transactions

Document Features

Summary Cards
Displays key metrics at the top:
  • Total Income (with currency)
  • Total Expenses (with currency)
  • Net Balance (calculated)
Transaction Table
Styled table with:
  • Colored badges for income/expense types
  • Category and account information
  • Formatted dates and amounts
  • Responsive design optimized for print
Header Information
  • Generation timestamp
  • User ID (truncated for privacy)
  • Account filter name (if applied)
  • Total transaction count

Example Request

curl -X GET "https://api.yourfinanceapp.com/api/reports/export/pdf/visual" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -o visual_report.pdf

Implementation Details

The visual PDF uses:
  • Handlebars templates for HTML generation
  • Puppeteer headless browser for PDF rendering
  • Shared browser instance (initialized on module startup)
  • Background colors and CSS fully rendered

Error Handling

If Puppeteer is not initialized (e.g., Docker environment issues), the endpoint returns:
{
  "message": "El servicio de reportes visuales no está disponible. Intente más tarde.",
  "error": "PUPPETEER_NOT_READY"
}
Status Code: 503 Service Unavailable

Comparison

FeatureTable PDFVisual PDF
SpeedFast (~200-500ms)Slower (~1-3s)
LibraryPDFKit-TablePuppeteer
File SizeSmallerLarger
StylingBasicRich/Custom
Best ForLarge datasets, quick exportsPresentations, client reports
DependenciesNative (always available)Requires Puppeteer/Chromium

Use Cases

Table PDF

  • Quick transaction exports for accounting
  • High-volume data downloads
  • Server environments with limited resources
  • Automated batch reporting

Visual PDF

  • Client-facing reports and presentations
  • Monthly/quarterly summary reports
  • Marketing materials with branding
  • Executive dashboards

Performance Notes

  • Both variants limit to 2,000 most recent transactions
  • Transactions are ordered by date (descending)
  • Soft-deleted records are excluded
  • Amount calculations happen server-side before rendering

Server Requirements

Visual PDF requires Puppeteer with Chromium. Ensure your deployment environment supports headless browsers:
  • Sufficient memory (recommend 512MB+ free)
  • Chrome/Chromium dependencies installed
  • Shared browser instance managed by NestJS lifecycle

Build docs developers (and LLMs) love