Comments (17)
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.
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:
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.
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.
@MatthewHerbst all not working! can you help me!
from react-to-print.
@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.
Yeah sure @MatthewHerbst, would be glad to do that ๐ฏ
Done, #394
from react-to-print.
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.
@simonschllng Sorry for the delayed response. So you're proposing two different solutions:
- Adding a prop called 'pageStyle' where a user can specify styles for the page itself
- 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.
First option is more appropriate.
from react-to-print.
Anyone want to take this work on up on the first option?
from react-to-print.
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.
@NguyenTheSon does it not work in general, or does it just not work with media/other queries?
from react-to-print.
@gregnb Any concrete solution, on how one can give page margins using @page
CSS rule, while using react-to-print?
from react-to-print.
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.
@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.
from react-to-print.
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)
- Superscripts <sup/> and subscripts <sub/> HOT 1
- react-to-print custom print html content dev vs prod discrepancy HOT 4
- [BUG] [TEMPORARY FIX] - Print container on Chrome + MUI is hiding `Header and Footers` option as default behavior HOT 5
- The FOOTER to only display at the LAST PAGE HOT 3
- codesandbox examples are not loading HOT 2
- onAfterPrint is called before print iframe appears HOT 1
- On mobile devices are not truncated accordingly ref HOT 1
- Add Border to every Page HOT 4
- Add dynamic colors to print function HOT 1
- How to check that the user click on Save in `onAfterPrint`? HOT 2
- getting Supplied Data is not a valid base64-String jsPDF.convertStringToImageData erorr while directly downloading image HOT 1
- Border top and bottom HOT 1
- Save as PDF hangs in print view HOT 1
- Blank PDF when trying to generate in production. HOT 2
- How should i handle large data to print? HOT 8
- Why does it render different content when in im browsing in mobile HOT 3
- Blank Page while printing after a certain period of time HOT 9
- How to add style using PageStyle prop, without it overriding componentโs style HOT 5
- Warning: findDOMNode is deprecated outside StrictMode. HOT 4
- Unhandled error when trying to print not fully loaded canvas elements HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-to-print.