npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@react-pdf-levelup/server

v1.1.3

Published

Utilidad de frontend para decodificar un PDF en base64 generados con @react-pdf-levelup/core y descargarlo/abrirlo en el navegador.

Downloads

28

Readme

@react-pdf-levelup/server

Utilidad de servidor para renderizar componentes de React a PDF utilizando un pool de workers para no bloquear el hilo principal de Node.js. Este paquete es parte del ecosistema de @react-pdf-levelup.

Instalación

npm install @react-pdf-levelup/server

Uso

Este paquete expone la función generatePDFonWorker que renderiza un componente de React a un PDF en un hilo de trabajo separado.

generatePDFonWorker(options)

Renderiza un template de React a PDF. A diferencia de un entorno de frontend, en el backend se debe proveer la ruta absoluta al componente que se quiere renderizar.

Parámetros:

  • options (objeto):
    • templatePath (string, requerido): Ruta absoluta al archivo del componente de React que se usará como plantilla. El componente debe tener un export default.
    • data (any, opcional): Datos que se pasarán como props al componente de la plantilla.
    • output ("base64" | "buffer", opcional): Formato de salida. Por defecto es "base64".

Retorna: Promise<string | Buffer> - Una promesa que se resuelve con el PDF generado en el formato de salida especificado.

Ejemplo:

import { generatePDFonWorker, closePDFPool } from "@react-pdf-levelup/server";
import path from "path";

async function crearFactura() {
  const datosFactura = {
    numero: "001",
    cliente: "Juan Perez",
    items: [
      { descripcion: "Producto A", cantidad: 2, precio: 10 },
      { descripcion: "Producto B", cantidad: 1, precio: 20 },
    ],
  };

  const templatePath = path.resolve("./ruta/a/mi/plantilla/Factura.js");

  try {
    const pdfBase64 = await generatePDFonWorker({
      templatePath: templatePath,
      data: datosFactura,
    });

    console.log("PDF generado en base64:", pdfBase64);

    // Si se necesita el buffer:
    const pdfBuffer = await generatePDFonWorker({
      templatePath: templatePath,
      data: datosFactura,
      output: "buffer",
    });

    console.log("PDF generado como Buffer:", pdfBuffer);

  } catch (error) {
    console.error("Error generando el PDF:", error);
  } finally {
    // Es importante cerrar el pool de workers cuando la aplicación se apaga.
    await closePDFPool();
  }
}

crearFactura();

closePDFPool()

Cierra el pool de workers de manera ordenada. Es importante llamar a esta función cuando la aplicación se va a detener para liberar recursos.

Cómo funciona

Este paquete utiliza la librería piscina para gestionar un pool de workers. La función generatePDFonWorker delega la tarea de renderizar el PDF a uno de estos workers.

Dentro del worker, se utiliza @react-pdf/renderer para convertir el componente de React en un stream de PDF, que luego se retorna como un Buffer al hilo principal. Este enfoque evita bloquear el event loop de Node.js con una tarea intensiva en CPU como es la generación de un PDF, mejorando el rendimiento y la escalabilidad de la aplicación.