Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

292
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!