Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

297
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda