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

274
Vistas
save-svg-as-png not loading the svg css, while downloading the svg as png

I am using save-svg-as-png module to download generated svg from d3 hierarchy tree to png.

Below is the svg generated in browser

enter image description here

But when I download it, some css are missing due to which graph is unreadable

enter image description here

Below is the code i am using to download

var saveSvgToPng = document.getElementById("download-button");
saveSvgToPng.onclick = function () {
  saveSvgAsPng(d3.select('svg').node(), "dia.png", {
    scale: 2,
  });
};

How do I resolve this issue.

Thanks in advance!

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

0

To all who are facing this issue. As suggested by @RobertLongson in the comment, it worked when I switched to inline css instead of external css.

Code with external css which was causing the issue

nodes
    .append("text")
    .attr("font-size", "12px")
    .attr("text-anchor", "middle")
    .text(function (d) {
        return `${d.data.name}`
    })

External css

text {
  text-shadow: -1px -1px 3px white, -1px 1px 3px white, 1px -1px 3px white,
      1px 1px 3px white;
  cursor: pointer;
  font-family: "Playfair Display", serif;
}

Code with inline css, which fixed the issue

nodes
    .append("text")
    .attr("font-size", "12px")
    .attr("text-anchor", "middle")
    .style(
      "text-shadow",
      `-1px -1px 3px white, -1px 1px 3px white, 1px -1px 3px white,
      1px 1px 3px white`
    )
    .style("cursor", "pointer")
    .style("font-family", `"Playfair Display", serif`)
    .text(function (d) {
        return `${d.data.name}`
    })

Hope this helps someone!

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