Giter VIP home page Giter VIP logo

Comments (21)

shawnco avatar shawnco commented on July 19, 2024 66

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

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

from react-to-print.

jesobreira avatar jesobreira commented on July 19, 2024 13

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;
}

from react-to-print.

Zuzze avatar Zuzze commented on July 19, 2024 9

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>

from react-to-print.

eric-burel avatar eric-burel commented on July 19, 2024 5

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).

from react-to-print.

louidorjp avatar louidorjp commented on July 19, 2024 3

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

from react-to-print.

hbrannan avatar hbrannan commented on July 19, 2024 2

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;
    }
}

from react-to-print.

MatthewHerbst avatar MatthewHerbst commented on July 19, 2024 2

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

from react-to-print.

kaydeniz avatar kaydeniz commented on July 19, 2024 1

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.

from react-to-print.

fizzvr avatar fizzvr commented on July 19, 2024 1

The FAQ is clear Page Breaks 🍻

from react-to-print.

harishkoninti avatar harishkoninti commented on July 19, 2024 1

CSS property page-break-inside worked for me
@media print { div.qandA{ page-break-inside: avoid; } }
Here my div className is "qandA" and wrap all elements in one div which you want to show on one page

from react-to-print.

Tevvek avatar Tevvek commented on July 19, 2024 1

@kaydeniz Hi! Just stumbled upon this thread and decided to share my workaround. So my guess is that you were using the right structure for a table i.e. <TableHead /> but what happens is that the default behaviour of the html tag for the table head is repeating itself when printing in a new page and that somehow messes with the rest of the styles.
So I removed the table head and added the head row inside the body twitching the styles so it looks like the actual head. For now this is the best workaround I found until I figure out what in MUI is messing with the printing.

from react-to-print.

MatthewHerbst avatar MatthewHerbst commented on July 19, 2024

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

from react-to-print.

balzee avatar balzee commented on July 19, 2024

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 .

from react-to-print.

MatthewHerbst avatar MatthewHerbst commented on July 19, 2024

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

from react-to-print.

zzq0324 avatar zzq0324 commented on July 19, 2024

@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.

from react-to-print.

hrafaelveloso avatar hrafaelveloso commented on July 19, 2024

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...

from react-to-print.

MatthewHerbst avatar MatthewHerbst commented on July 19, 2024

@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

from react-to-print.

kaydeniz avatar kaydeniz commented on July 19, 2024

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.

from react-to-print.

hrafaelveloso avatar hrafaelveloso commented on July 19, 2024

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...

from react-to-print.

MatthewHerbst avatar MatthewHerbst commented on July 19, 2024

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

from react-to-print.

AchmadWahyu avatar AchmadWahyu commented on July 19, 2024

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?

from react-to-print.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.