MatthewHerbst / react-to-print

Print React components in the browser. Supports Chrome, Safari, Firefox and EDGE
MIT License
2.06k stars 221 forks source link

How to add style using PageStyle prop, without it overriding component’s style #705

Closed raosudheesh closed 1 week ago

raosudheesh commented 4 months ago

I’m trying to adjust the height and width of the pages before printing. I’m trying to use pageStyle, but it overrides the component style. All I want to do is adjust the page size. Could anyone help?

MatthewHerbst commented 4 months ago

Hello. Have you seen the README section about setting the page size? Please let us know i that works for you

raosudheesh commented 4 months ago

Hey @MatthewHerbst that overrides the existing style of the component. I don’t want to do that

MatthewHerbst commented 4 months ago

that overrides the existing style of the component. I don’t want to do that

Not sure I understand, it doesn't change any components. And you can wrap it in a media tag (as shown in the example) to make it only apply during printing

raosudheesh commented 4 months ago

I tied with

pageStyle : ‘@media print {
  @page {
    size: 50mm 150mm;
  }
}’

it did override the existing styles and applied only these

MatthewHerbst commented 4 months ago

Set the styles in your normal CSS, not using pageStyle