Generar facturas en HTML y exportar a PDF con Cerewro

Cerewro puede generar facturas profesionales en HTML con todos los campos legales requeridos, calcular automáticamente impuestos y totales, y exportarlas a PDF de alta calidad usando Puppeteer (headless Chrome) o wkhtmltopdf. Sin software de facturación externo.

Estructura legal de una factura en España

Campo obligatorioDescripción
Número y serieNumeración correlativa e ininterrumpida
Fecha de expediciónFecha en que se emite la factura
Datos del emisorNombre/razón social, NIF, dirección fiscal
Datos del receptorNombre/razón social, NIF, dirección (B2B)
DescripciónConcepto de los bienes o servicios
Base imponibleImporte sin IVA
Tipo IVA21%, 10%, 4% o exento
Cuota IVAImporte del IVA
TotalBase + IVA

Generar factura desde Cerewro

Cerewro Chat
Genera la factura número FA-2026-0042 para:
- Emisor: Mi Empresa SL, NIF B12345678, Calle Mayor 1, Madrid
- Cliente: Empresa Cliente SA, NIF A87654321, Av. Diagonal 100, Barcelona
- Líneas:
  * 5 horas de consultoría web a 120€/h (IVA 21%)
  * 1 mes hosting premium a 49€/mes (IVA 21%)
- Fecha: hoy
- Vencimiento: 30 días
- Forma de pago: transferencia bancaria IBAN ES12 3456 7890 1234 5678 9012
Genera el HTML y luego conviértelo a PDF
Plantilla HTML de factura generada
<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <style>
    body { font-family: Arial, sans-serif; font-size: 12px; color: #333; margin: 40px; }
    .header { display: flex; justify-content: space-between; margin-bottom: 30px; }
    .logo { font-size: 24px; font-weight: bold; color: #2563eb; }
    .invoice-title { font-size: 28px; color: #2563eb; text-align: right; }
    table { width: 100%; border-collapse: collapse; margin-top: 20px; }
    th { background: #2563eb; color: white; padding: 10px; text-align: left; }
    td { padding: 8px 10px; border-bottom: 1px solid #e5e7eb; }
    .totals { margin-top: 20px; float: right; min-width: 300px; }
    .total-final { font-size: 16px; font-weight: bold; background: #f0f9ff; padding: 10px; }
    .footer { margin-top: 60px; font-size: 10px; color: #6b7280; border-top: 1px solid #e5e7eb; padding-top: 10px; }
  </style>
</head>
<body>
  <div class="header">
    <div>
      <div class="logo">Mi Empresa SL</div>
      <p>NIF: B12345678<br>Calle Mayor 1, 28001 Madrid<br>info@miempresa.es</p>
    </div>
    <div>
      <div class="invoice-title">FACTURA</div>
      <p style="text-align:right"><strong>Nº:</strong> FA-2026-0042<br>
      <strong>Fecha:</strong> 26/08/2026<br>
      <strong>Vence:</strong> 25/09/2026</p>
    </div>
  </div>
  <!-- ... líneas de factura, totales, pie de página ... -->
</body>
</html>

Exportar a PDF con Puppeteer

Script Node.js para generar PDF
const puppeteer = require('puppeteer');
const fs = require('fs');

async function htmlToPdf(htmlPath, pdfPath) {
  const browser = await puppeteer.launch({ headless: 'new' });
  const page    = await browser.newPage();

  const html = fs.readFileSync(htmlPath, 'utf8');
  await page.setContent(html, { waitUntil: 'networkidle0' });

  await page.pdf({
    path:   pdfPath,
    format: 'A4',
    margin: { top: '15mm', bottom: '15mm', left: '15mm', right: '15mm' },
    printBackground: true
  });

  await browser.close();
  console.log(`PDF generado: ${pdfPath}`);
}

htmlToPdf('factura-FA-2026-0042.html', 'factura-FA-2026-0042.pdf');
Cerewro Chat — Generar PDF directamente
Genera la factura FA-2026-0042 como HTML y conviértela a PDF guardándola en C:\facturas\2026\

Exportar con wkhtmltopdf (sin Node.js)

Instalación y uso
# Instalar
choco install wkhtmltopdf -y

# Convertir HTML a PDF (desde CMD/PowerShell)
wkhtmltopdf --page-size A4 --margin-top 15mm --margin-bottom 15mm `
  factura-FA-2026-0042.html factura-FA-2026-0042.pdf
Factura electrónica FacturaE: Si necesitas emitir facturas electrónicas en formato FacturaE (obligatorio para Administración Pública española), pide a Cerewro: "Genera el XML FacturaE 3.2.2 para esta factura". La IA genera el XML con firma digital incluida.