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

303
Vistas
How to add a space, break or div at specific height dynamically?

So basically I want to print out a page as a pdf from a react app, that include multiple components. number of components change from 4 up to 12 and the height of the components also change based on content from the store.

I need every 900px(size of my a4 page) to add a space so that none of the components get split between pages. or to split the hole page in to even 900px parts based on how many components are rendered.

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

0

This is not a question can be answered with code snippet. I will explain how i would tackle with this problem.

Steps right after the the print event (on button click or automated...)

  1. I would get each components current height (as you mentioned 4 up to 12 components)
   const element = document.getElementById('element');
   element.offsetHeight // height
  1. I would create placeholder component (div), which would be used to fill the gap vertically between components to be printed.
   const Placeholder = ({height}) => (
      <div style={{height: `${height}px` }}>  </div>
   )
  1. I would start looping all the components until they can fit into 900px. When the chunk reaches the 900px i would fill the gap with placeholder component. That would force rest of the components to move to next page. E.g. Let's say:
Component 1 is 300px
Component 2 is 300px
Component 3 is 700px
Component 4 is 300px
loop {
  // first page
  <Component1 />
  <Component2 />
  <Placeholder height={300} />
  // second page
  <Component3 />
  <Placeholder height={200} />
  <Component4 />
  <Placeholder height={600} />
}
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