Cómo generar un archivo PDF en Node.js Darrius Serrant Actualizado:agosto 19, 2025 Download IronPDF Descarga npm Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article Unlock the full potential of PDF generation in your Node.js applications by watching our tutorial, where you'll learn to transform HTML, web pages, and images into dynamic PDFs using IronPDF, and discover how this powerful tool can streamline your development process—subscribe now and start your free trial! más... In this comprehensive tutorial, we delve into generating PDF files in Node.js using the IronPDF library. We begin by installing the necessary packages and setting up the environment. The tutorial covers importing essential modules, including PDF Generator, PDF Document, and IronPDF Global Config, along with the FS module from Node.js. We demonstrate creating PDFs from HTML strings by converting a simple 'Hello World' HTML tag into a PDF. Next, we explore converting a Wikipedia page URL about PDFs into a PDF document, showcasing IronPDF's ability to capture web pages in detail. The tutorial also covers converting images into a single PDF by filtering JPEGs from a directory and using PDF Generator's image-to-PDF functionality. By running the code in the terminal, we successfully generate and review the PDFs, displaying IronPDF's capabilities to convert various sources into PDF documents. This powerful tool significantly enhances PDF generation possibilities in Node.js applications. For more tutorials and to explore IronPDF's features, subscribe to Iron Software's channel and sign up for a trial to experience the software firsthand.# Bash code to install the IronPDF library in your Node.js project.npm install ironpdf # Bash code to install the IronPDF library in your Node.js project.npm install ironpdf SHELL // Import necessary modules from IronPDF and Node.jsconst { PDFGenerator, PDFDocument, IronPDFGlobalConfig } = require('ironpdf');const fs = require('fs'); // File system module for handling file operations// Initialize PDF Generatorconst pdfGenerator = new PDFGenerator();async function generatePdfFromHtml() { // HTML content to be converted into a PDF const htmlContent = '<h1>Hello World</h1>'; try { // Convert HTML string to a PDF document const pdfDoc = await pdfGenerator.fromHtml(htmlContent); // Save the generated PDF document to a file await pdfDoc.saveAs('hello_world.pdf'); console.log('PDF generated successfully from HTML string.'); } catch (error) { console.error('Error generating PDF from HTML:', error); }}async function generatePdfFromWebPage() { // URL of the web page to be converted into a PDF const url = 'https://en.wikipedia.org/wiki/PDF'; try { // Convert web page URL to a PDF document const pdfDoc = await pdfGenerator.fromUrl(url); // Save the generated PDF document to a file await pdfDoc.saveAs('wikipedia_pdf.pdf'); console.log('PDF generated successfully from webpage URL.'); } catch (error) { console.error('Error generating PDF from webpage:', error); }}async function generatePdfFromImages() { // Directory containing images const imageDir = './images'; const imageFiles = fs.readdirSync(imageDir); try { // Filter only JPEG files from the directory const jpegImages = imageFiles.filter(file => file.endsWith('.jpeg')); // Convert filtered images to a single PDF document const pdfDoc = await pdfGenerator.fromImages(jpegImages.map(img => `${imageDir}/${img}`)); // Save the generated PDF document to a file await pdfDoc.saveAs('images.pdf'); console.log('PDF generated successfully from images.'); } catch (error) { console.error('Error generating PDF from images:', error); }}// Execute the functions to generate PDFsgeneratePdfFromHtml();generatePdfFromWebPage();generatePdfFromImages(); // Import necessary modules from IronPDF and Node.jsconst { PDFGenerator, PDFDocument, IronPDFGlobalConfig } = require('ironpdf');const fs = require('fs'); // File system module for handling file operations// Initialize PDF Generatorconst pdfGenerator = new PDFGenerator();async function generatePdfFromHtml() { // HTML content to be converted into a PDF const htmlContent = '<h1>Hello World</h1>'; try { // Convert HTML string to a PDF document const pdfDoc = await pdfGenerator.fromHtml(htmlContent); // Save the generated PDF document to a file await pdfDoc.saveAs('hello_world.pdf'); console.log('PDF generated successfully from HTML string.'); } catch (error) { console.error('Error generating PDF from HTML:', error); }}async function generatePdfFromWebPage() { // URL of the web page to be converted into a PDF const url = 'https://en.wikipedia.org/wiki/PDF'; try { // Convert web page URL to a PDF document const pdfDoc = await pdfGenerator.fromUrl(url); // Save the generated PDF document to a file await pdfDoc.saveAs('wikipedia_pdf.pdf'); console.log('PDF generated successfully from webpage URL.'); } catch (error) { console.error('Error generating PDF from webpage:', error); }}async function generatePdfFromImages() { // Directory containing images const imageDir = './images'; const imageFiles = fs.readdirSync(imageDir); try { // Filter only JPEG files from the directory const jpegImages = imageFiles.filter(file => file.endsWith('.jpeg')); // Convert filtered images to a single PDF document const pdfDoc = await pdfGenerator.fromImages(jpegImages.map(img => `${imageDir}/${img}`)); // Save the generated PDF document to a file await pdfDoc.saveAs('images.pdf'); console.log('PDF generated successfully from images.'); } catch (error) { console.error('Error generating PDF from images:', error); }}// Execute the functions to generate PDFsgeneratePdfFromHtml();generatePdfFromWebPage();generatePdfFromImages(); JAVASCRIPT
Actualizadoagosto 19, 2025 Cómo convertir un PDF a un archivo de imagen en Node.js Este tutorial en video te guía a través de cómo convertir un archivo PDF en archivos de imagen usando Iron PDF en JavaScript. Aprende a importar documentos PDF, extraer páginas y guardarlas como imágenes BMP. Descubre cómo convertir páginas específicas de PDF y mejora tu aplicación con imágenes de alta calidad. Leer más
Actualizadoseptiembre 22, 2025 Cómo convertir HTML a PDF en Node js sin Pupateer | IronPDF Explore una guía completa sobre el uso de IronPDF para convertir HTML a PDF en Node.js. Este tutorial proporciona un enfoque paso a paso, ofreciendo una alternativa fiable a Puppeteer para una generación de PDF eficiente. Leer más
Actualizadoagosto 19, 2025 Cómo firmar un archivo PDF en Nodejs Este tutorial proporciona una guía completa sobre la firma de PDFs usando la biblioteca Iron PDF en un entorno Node.js. Cubre la instalación, configuración y ejecución, permitiendo a los usuarios agregar fácilmente firmas digitales a sus documentos PDF. Leer más
Actualizadoagosto 19, 2025 Cómo Leer Archivos PDF en Node.js Este tutorial guía a los desarrolladores sobre cómo leer PDFs usando Node.js con la Biblioteca Iron PDF. Cubre el proceso de instalación, importación de los módulos necesarios, y demuestra las funciones asíncronas usadas para extraer texto y metadatos de archivos PDF. Descubre un enfoque sencillo para manejar PDFs en aplicaciones de Node.js. Leer más
Actualizadoagosto 19, 2025 Cómo convertir HTML a PDF en Node js sin Puppeteer Este tutorial explora la conversión de HTML a PDF en Node.js usando la biblioteca Iron PDF, evitando Puppeteer. Cubre la instalación, conversión básica de cadenas HTML, tareas más complejas como convertir páginas web, y trabajar con archivos HTML offline. La guía destaca la simplicidad y versatilidad de Iron PDF. Leer más
Actualizadoagosto 19, 2025 Cómo convertir HTML a PDF en Nodejs Este tutorial te guía a través de la conversión de HTML a PDF en Node.js usando Iron PDF. Aprende a instalar los paquetes necesarios, configurar tu entorno y crear PDFs a partir de cadenas de HTML, archivos y páginas web. Descubre la versatilidad de Iron PDF para generar PDFs de calidad profesional. Leer más
Producto completamente funcional Obtén 30 días de producto completamente funcional.Instálalo y ejecútalo en minutos.
Soporte técnico 24/5 Acceso completo a nuestro equipo de soporte técnico durante tu prueba del producto