Giter VIP home page Giter VIP logo

Comments (17)

nikhils4 avatar nikhils4 commented on July 1, 2024 4

I got the solution for this,

As I was using React, so made a function to get the page margins and called the same inside style tag in the JSX, and it worked,

const getPageMargins = () => {
  return `@page { margin: ${marginTop} ${marginRight} ${marginBottom} ${marginLeft} !important; }`;
};
<style>{getPageMargins()}</style>

Hope it helps!

from react-to-print.

simonschllng avatar simonschllng commented on July 1, 2024 2

For me this is more a hack than a solution. The browser adds those headings and should give the user a way to remove them. My browser (google chrome 67) offers this option:
image

Could you at least make this optional? Like if you set property pageStyle="@page { size: auto; margin: 25mm; } }" it gets overwritten, if not it takes the current default?

from react-to-print.

gregnb avatar gregnb commented on July 1, 2024 1

I've taken care of this issue by adding a prop called pageStyle which you can then override everything and provide whatever styles you wish.

If you want nothing to be there simply:

 <ReactToPrint
    pageStyle={""}
 />

from react-to-print.

NguyenTheSon avatar NguyenTheSon commented on July 1, 2024 1

@MatthewHerbst all not working! can you help me!

from react-to-print.

MatthewHerbst avatar MatthewHerbst commented on July 1, 2024 1

@nikhils4 thanks for sharing! If you'd like, feel free to make a PR to add that to the CSS tricks section of the README! I'm happy to do that too if you'd like, but would love for you to take the git credit ๐Ÿ˜„

from react-to-print.

nikhils4 avatar nikhils4 commented on July 1, 2024 1

Yeah sure @MatthewHerbst, would be glad to do that ๐Ÿ’ฏ

Done, #394

from react-to-print.

codesignist avatar codesignist commented on July 1, 2024

As you might notice margin 0 removes the date/time from top.
https://github.com/gregnb/react-to-print/blob/725e060ed02a6077420f5be2897990b60f9ee46a/src/index.js#L160
Need an another solution.

from react-to-print.

gregnb avatar gregnb commented on July 1, 2024

@simonschllng Sorry for the delayed response. So you're proposing two different solutions:

  1. Adding a prop called 'pageStyle' where a user can specify styles for the page itself
  2. A prop to turn the default pageStyle off/on

If you want to submit a PR for solution 1 I would accept it. That way you can style it however you see fit. As pointed out it was added to remove the time, but I would be willing to allow users to override if it they really want to

from react-to-print.

codesignist avatar codesignist commented on July 1, 2024

First option is more appropriate.

from react-to-print.

gregnb avatar gregnb commented on July 1, 2024

Anyone want to take this work on up on the first option?

from react-to-print.

NguyenTheSon avatar NguyenTheSon commented on July 1, 2024

pageStyle not working! I want custom margin top, bottom.

pageStyles={'@media print { body { -webkit-print-color-adjust: exact; } @page { size: A4; margin: 200mm !important }}'}

from react-to-print.

MatthewHerbst avatar MatthewHerbst commented on July 1, 2024

@NguyenTheSon does it not work in general, or does it just not work with media/other queries?

from react-to-print.

nikhils4 avatar nikhils4 commented on July 1, 2024

@gregnb Any concrete solution, on how one can give page margins using @page CSS rule, while using react-to-print?

from react-to-print.

15tanvir avatar 15tanvir commented on July 1, 2024

Hii ,

I got the solution for this,

As I was using React, so made a function to get the page margins and called the same inside style tag in the JSX, and it worked,

const getPageMargins = () => {
  return `@page { margin: ${marginTop} ${marginRight} ${marginBottom} ${marginLeft} !important; }`;
};
<style>{getPageMargins()}</style>

Hope it helps!

Hi @nikhils4 can't we add a margin to the specific page only? As the above function added margin to all pages.

from react-to-print.

MatthewHerbst avatar MatthewHerbst commented on July 1, 2024

@15tanvir you'd have to make a class to apply it to and have that class only wrap content on the first page

from react-to-print.

15tanvir avatar 15tanvir commented on July 1, 2024

from react-to-print.

MatthewHerbst avatar MatthewHerbst commented on July 1, 2024

If you look at the docs, I think you want something like:

@page :first {
  /* Applies styles to the first page only */
}

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.