React-to-print: have you tried print multiple pages?

Created on 9 Oct 2018  ยท  19Comments  ยท  Source: gregnb/react-to-print

@gregnb have you tried print multiple pages? I have print one page with more than one page, but it only print first page. Can you tell me what should I do? Thank you!

Most helpful comment

Complete shot in the dark here but try adding this CSS somewhere:

@media print { html, body { height: initial !important; overflow: initial !important; }}

All 19 comments

Complete shot in the dark here but try adding this CSS somewhere:

@media print { html, body { height: initial !important; overflow: initial !important; }}

Hi, I've managed to print multiple pages but the cut is disgraceful, there is no bottom padding. I've played with page-break-inside, it does not work as expected (it tries to avoid the page break but cut the paragraph in 2).

Is this a bug or is there functionality that needs to be added?

I face the same issue too, I have a long table and can only print 1 page at a time and when i scroll and try again there is an akward cut .

Hi all. Could anyone please share a codepen or fiddle with an example so that I can play around with it and try and work on a fix? Thanks

@MatthewHerbst
I use rc-print instead, code just like this๏ผš
<Print title="" insertHead={false} otherStyle="@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }"><div></div></Print>

I hope it can help you.

When the Component I want to print only takes 1 page, everything works great.
I'm using Material-UI and I have tables that use material-table and this works great when the result is a single page file.
However, when it goes to multiple pages I can't:
. Break where I want (using css page-break-before) ;
. Bottom margin is inexistent, even with padding and margin-bottom...

I really need that functionality, and I lost at least 2 days trying to figure it out without success...

@hrafaelveloso PRs are welcome if you have any ideas on how best to do this! I haven't had too much time to look at this issue over the other issues in the codebase

I also struggled with styling/margins on multiple pages and found a workaround with viewport units:

<div className="container" style={{margin: "0", padding: "0"}}>
   <div style={{height: "90vh", padding: 5vh}}>
      page 1 content
   </div>
   <div style={{height: "90vh", padding: 5vh}}>
       page 2 content
    </div>
</div>

When the Component I want to print only takes 1 page, everything works great.
I'm using Material-UI and I have tables that use material-table and this works great when the result is a single page file.
However, when it goes to multiple pages I can't:
. Break where I want (using css page-break-before) ;
. Bottom margin is inexistent, even with padding and margin-bottom...

I really need that functionality, and I lost at least 2 days trying to figure it out without success...

Hi, did you find any solution for print of multiple pages. I'm using Material-UI template and i have long tables to print. I'm having problems at the top of page 2.

Hi, did you find any solution for print of multiple pages. I'm using Material-UI template and i have long tables to print. I'm having problems at the top of page 2.

Unfornately I can't figure out what the problem was, and I was forced to choose pdfmake...

Hi, did you find any solution for print of multiple pages. I'm using Material-UI template and i have long tables to print. I'm having problems at the top of page 2.

Unfornately I can't figure out what the problem was, and I was forced to choose pdfmake...

@hrafaelveloso thank you.

Mixed @shawnco's and @zzq0324's solutions and it worked well for me:

@media print {
  html, body {
    height: initial !important;
    overflow: initial !important;
    -webkit-print-color-adjust: exact;
  }
}

@page {
  size: auto;
  margin: 20mm;
}

Going to close this as a CSS issue. Thanks everyone for the solutions, and please feel free to continue talking about it here.

After playing for a while, the solution that worked for me was to treat page-break (-inside, etc.) more granularly than I had been.

I had been under the impression that my dynamically rendering react components' split would happen automatically as long as I didn't have overflow or display set incompatibly with print mode, but that wasn't what I observed.

Instead, my breaks appeared only once I both: added a .page-break class to the dynamically-rendering components that I envisioned could auto-break, and then applied the following styles:

@media all {
  .page-break {
     display: none;
  }
}

@media print {
  .page-break {
      display: block;
      page-break-before: auto;
    }
}

If anyone would like to add to the README FAQ with a generic solution to this I would be happy to accept that PR!

After playing for a while, the solution that worked for me was to treat page-break (-inside, etc.) more granularly than I had been.

I had been under the impression that my dynamically rendering react components' split would happen automatically as long as I didn't have overflow or display set incompatibly with print mode, but that wasn't what I observed.

Instead, my breaks appeared only once I both: added a .page-break class to the dynamically-rendering components that I envisioned could auto-break, and then applied the following styles:

@media all {
  .page-break {
     display: none;
  }
}

@media print {
  .page-break {
      display: block;
      page-break-before: auto;
    }
}

Hi @hbrannan , may i ask you a fiddle or codepen by the example of this multiple printing page for me to play around, please?

The FAQ is clear Page Breaks ๐Ÿป

I also struggled with styling/margins on multiple pages and found a workaround with viewport units:

<div className="container" style={{margin: "0", padding: "0"}}>
   <div style={{height: "90vh", padding: 5vh}}>
      page 1 content
   </div>
   <div style={{height: "90vh", padding: 5vh}}>
       page 2 content
    </div>
</div>

it's work for me
Screenshot from 2021-03-24 11-43-47

Was this page helpful?
0 / 5 - 0 ratings