Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

213
Vistas
Puppeteer PDF export doesn't render images

I try to export my HTML to a pdf file which works fine except that my images are not loaded. When I use the headless: false option I see the website with the image loaded, but when I export the PDF the image is just the default icon for a non-loaded image: image

My Code:

  const browser = await puppeteer.launch({ headless: false, args: ["--explicitly-allowed-ports=" + port] });
  const page = await browser.newPage();
  await page.setContent(content, { waitUntil: "networkidle0" }); // I also tried "load"
  await page.waitFor(2000); // The page should be loaded for sure
  await page.emulateMediaType("print");
  await page.pdf({ path: "F:\\Desktop\\file.pdf", format: "a4" });
  await browser.close();

I already tried media types "screen" and "print", both don't work. The HTML of the web page is:

<html xmlns="http://www.w3.org/1999/xhtml">
   <head></head>
   <body>
      <p>Es handelt sich hierbei um ein File:</p>
      <p><strong>File:</strong></p>
      <sm-file class="mceNonEditable" title="Bright Solutions _ Digitale Projekt-Checklisten.pdf" data-uuid="AD13E638-6DB5-4DCD-A7F6-03D66C1D24DF" data-name="Bright Solutions _ Digitale Projekt-Checklisten.pdf">
         <img src="http://localhost:6666/icon_file.svg" width="20px" height="20px" />
         <hr />
         Bright Solutions _ Digi... ten.pdf
      </sm-file>
      <p>Hier kommt dann noch ein Bild hinzu!</p>
   </body>
</html>

Does anyone know what I can do so that the image in the PDF is rendered correctly?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The reason is ERR_UNSAFE_PORT! The port 6666 is considered unsafe. A full list of unsafe ports can be seen here: https://superuser.com/questions/188058/which-ports-are-considered-unsafe-by-chrome So just change the port of the webserver to something that is not on this list and everything works fine.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda