React-Pdf Org
React-Pdf Org
React-pdf
React renderer for creating PDF files on the browser and server.
v3
Compatibility
Rendering process
SVG Images
Hooks
Styling
Fonts
Donate
Using npm
Using Yarn
Using pnpm
Using Bun
Since a renderer simply implements how elements render into something, you still need to have React to
make it work (and react-dom for client-side document generation). You can find instructions on how to
do that here.
This is where things start getting interesting. React-pdf exports a set of React primitives that enable you
to render things into your document very easily. It also has an API for styling them, using CSS properties
and Flexbox layout.
// Create styles
const styles = StyleSheet.create({
page: {
flexDirection: 'row',
backgroundColor: '#E4E4E4'
},
section: {
margin: 10,
padding: 10,
flexGrow: 1
}
});
This will produce a PDF document with a single page. Inside, two different blocks, each of them rendering
a different text. These are not the only valid primitives you can use. Please refer to the Components or
Examples sections for more information.
React-pdf enables you to render the document in two different environments: web and server. The
process is essentially the same, but catered to needs of each environment.
Save in a file
import ReactPDF from '@react-pdf/renderer';
Render to a stream
ReactPDF.renderToStream(<MyDocument />);
Quick start guide
Compatibility
4. Have fun!
Maybe the most important step — make use of all react-pdf capabilities to create beautiful and awesome
documents!
Compatibility →