Incrustación de mapas de bits e imágenes To ensure that HTML content does not require an internet connection to retrieve data, images can be embedded into HTML as base64. Embedding an image in HTML as base64 requires loading the image and converting its information to base64. Below is a complete example that demonstrates how to read an image file, convert it to a base64 string, and then embed it into an HTML document. Finally, it shows how to generate a PDF from this HTML using IronPDF. Explanation: Image to Base64 Encoding: encodeImageToBase64(filePath): A function that reads the image file and converts it to a base64 string asynchronously. Uses fs.readFile to read the image file. If successful, converts the data to a base64 string and resolves it. HTML Content Setup: createHtmlContent(base64Data): Constructs HTML content with the embedded base64 image data within an img tag. PDF Generation: generatePdf(filePath): Main function that orchestrates the process by first calling encodeImageToBase64 and then createHtmlContent, followed by creating a PDF via IronPdf. Uses IronPdf.PdfDocument.fromHtml to generate a PDF document from the HTML content. Saves the generated PDF using pdf.saveAs. Execution: Calls generatePdf with the path to the desired image file. This script effectively combines reading an image, converting it to base64 for HTML embedding, and rendering a PDF using IronPDF. Explore the Complete Base64 Image Embedding Example Enlaces de Documentos Ver en Github Tutorial Relacionado Guía de Cómo Hacer Relacionada Documentación de Clase Obtener Paquetes de Idiomas Descargar IronPDF DLL Reportar un problema en esta página ¿Listo para empezar? Versión: 2025.11 recién lanzado Instalación gratuita con npm Ver Licencias
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