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

127
Vistas
How to find exact length of pixel in mm

I am using an HTML, CSS, js template, and converting it to pdf with the android app. I had a problem detecting when will next page break so I can put an element on the next page and change its design. I am trying with calculating the distance from the top of the page to the bottom of that element, and then check if that element ends after the page ends.

<script>
  const pageHeight = 275;            //page height without margins in mm
  const pixelSize = 0.2645833333;    //pixel size in mm
  const normalGraph = document.getElementById("normal-graph-block");
  const breakGraph = document.getElementById("break-graph-block");
  const pixelRatio = window.devicePixelRatio;

  function myFunction() {
    //Get distance from top of page to top of element  plus element height
    //multiplyed by pixel size to get distance in mm
    const graphBottomPos = 
      (normalGraph.getBoundingClientRect().top + normalGraph.offsetHeight) * pixelSize;
    if ( graphBottomPos > pageHeight ) {
      normalGraph.style.display = "none";
      breakGraph.style.display = "block";
    }
  }

  window.onload = myFunction;
</script>

It's not working well and I get different values on different phones. I think I need to use devicePixelRatio to compensate for that but I could make it work, even with it.

Please don't tell me to use page-break-before, after.., because I need to hide that element after a page break and show a similar one with a different style.

It would be much better if I could detect that page break somehow, but since it is not <br> element, i think that is not possibile.

about 4 years ago · Juan Pablo Isaza
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