React-pdf (2024)

Styling

Because a document without styles would be very boring, react-pdf ships a powerful styling solution using CSS and Flexbox.

StyleSheet API

React-pdf also sticks with the primitives specs when it comes to styling.

StyleSheet.create()

Create a stylesheet. This method expects a valid JS object as only argument (containing as much css definitions as you want) and returns an object that you can pass down to components via the style prop

import React from 'react';import { Page, Text, View, Document, StyleSheet } from '@react-pdf/renderer';const styles = StyleSheet.create({ page: { backgroundColor: 'tomato' }, section: { color: 'white', textAlign: 'center', margin: 30 }});const doc = ( <Document> <Page size="A4" style={styles.page}> <View style={styles.section}> <Text>Section #1</Text> </View> </Page> </Document>);ReactPDF.render(doc);

Inline styling

There's no need to call StyleSheet.create in order to style components. You can also just pass a plain JS object to the style prop and react-pdf will get the job done.

import React from 'react';import { Page, Text, View, Document } from '@react-pdf/renderer';const MyDocument = () => ( <Document> <Page size="A4" style={{ backgroundColor: 'tomato' }}> <View style={{ color: 'white', textAlign: 'center', margin: 30 }}> <Text>Section #1</Text> </View> </Page> </Document>);

Mixing both solutions

The style prop also accepts an Array as value, containing any possible combination of the last two alternatives

import React from 'react';import { Page, Text, View, Document, StyleSheet } from '@react-pdf/renderer';const styles = StyleSheet.create({ page: { backgroundColor: 'tomato' }, section: { textAlign: 'center', margin: 30 }});const MyDocument = () => ( <Document> <Page size="A4" style={styles.page}> <View style={[styles.section, { color: 'white' }]}> <Text>Section #1</Text> </View> </Page> </Document>);

Protip: This can be useful when you want to apply both predefined styles, and styles based on props

Media queries

There may be times in which you'll need to apply different styles based on the document context. For that, we provide media-queries support (just as you would do it for the web!). You can query based on both width and height (min and max), and also orientation:

import React from 'react';import { Page, Text, View, Document, StyleSheet } from '@react-pdf/renderer';const styles = StyleSheet.create({ section: { width: 200, '@media max-width: 400': { width: 300, }, '@media orientation: landscape': { width: 400, }, }});const MyDocument = () => ( <Document> <Page size="A4" style={styles.page}> <View style={styles.section}> <Text>Section #1</Text> </View> </Page> </Document>);

Valid units

pt (default. Based on the standard 72 dpi PDF document)

in inches

mm millimeters

cm centimeters

% percentage

vw viewport/page width

vh viewport/page height

Valid CSS properties

Flexbox

  • alignContent
  • alignItems
  • alignSelf
  • flex
  • flexDirection
  • flexWrap
  • flexFlow
  • flexGrow
  • flexShrink
  • flexBasis
  • justifyContent

Layout

  • bottom
  • display
  • left
  • position
  • right
  • top
  • overflow
  • zIndex

Dimension

  • height
  • maxHeight
  • maxWidth
  • minHeight
  • minWidth
  • width

Color

  • backgroundColor
  • color
  • opacity

Text

  • fontSize
  • fontFamily
  • fontStyle
  • fontWeight
  • letterSpacing
  • lineHeight
  • maxLines
  • textAlign
  • textDecoration
  • textDecorationColor
  • textDecorationStyle
  • textIndent
  • textOverflow
  • textTransform

Sizing/positioning

  • object-fit
  • object-position

Margin/padding

  • margin
  • marginHorizontal
  • marginVertical
  • marginTop
  • marginRight
  • marginBottom
  • marginLeft
  • padding
  • paddingHorizontal
  • paddingVertical
  • paddingTop
  • paddingRight
  • paddingBottom
  • paddingLeft

Transformations

  • transform:rotate
  • transform:scale
  • transform:scaleX
  • transform:scaleY
  • transform:translate
  • transform:translateX
  • transform:translateY
  • transform:skew
  • transform:skewX
  • transform:skewY
  • transform:matrix
  • transformOrigin

Borders

  • border
  • borderColor
  • borderStyle
  • borderWidth
  • borderTop
  • borderTopColor
  • borderTopStyle
  • borderTopWidth
  • borderRight
  • borderRightColor
  • borderRightStyle
  • borderRightWidth
  • borderBottom
  • borderBottomColor
  • borderBottomStyle
  • borderBottomWidth
  • borderLeft
  • borderLeftColor
  • borderLeftStyle
  • borderLeftWidth
  • borderTopLeftRadius
  • borderTopRightRadius
  • borderBottomRightRadius
  • borderBottomLeftRadius
React-pdf (2)
React-pdf (2024)
Top Articles
What Are the Elements of a Product Liability Claim?
Strategies And Secrets of High Frequency Trading (HFT) Firms
Friskies Tender And Crunchy Recall
Play FETCH GAMES for Free!
123Movies Encanto
Euro (EUR), aktuální kurzy měn
Blackstone Launchpad Ucf
Large storage units
What Was D-Day Weegy
Best Fare Finder Avanti
Accuradio Unblocked
Seattle Rpz
Rainfall Map Oklahoma
Aldi Sign In Careers
What is Rumba and How to Dance the Rumba Basic — Duet Dance Studio Chicago | Ballroom Dance in Chicago
Theresa Alone Gofundme
Check From Po Box 1111 Charlotte Nc 28201
Best Forensic Pathology Careers + Salary Outlook | HealthGrad
Craigslist In Flagstaff
Free Online Games on CrazyGames | Play Now!
Nhl Tankathon Mock Draft
Hdmovie 2
Aps Day Spa Evesham
Program Logistics and Property Manager - Baghdad, Iraq
Pearson Correlation Coefficient
Mtr-18W120S150-Ul
Pirates Of The Caribbean 1 123Movies
Japanese Mushrooms: 10 Popular Varieties and Simple Recipes - Japan Travel Guide MATCHA
Ou Class Nav
Geico Car Insurance Review 2024
As families searched, a Texas medical school cut up their loved ones
ATM, 3813 N Woodlawn Blvd, Wichita, KS 67220, US - MapQuest
Pdx Weather Noaa
RFK Jr., in Glendale, says he's under investigation for 'collecting a whale specimen'
Weekly Math Review Q4 3
Movies123.Pick
Waffle House Gift Card Cvs
Die Filmstarts-Kritik zu The Boogeyman
Giantess Feet Deviantart
301 Priest Dr, KILLEEN, TX 76541 - HAR.com
Yogu Cheshire
Hireright Applicant Center Login
More News, Rumors and Opinions Tuesday PM 7-9-2024 — Dinar Recaps
Cnp Tx Venmo
Windshield Repair & Auto Glass Replacement in Texas| Safelite
Despacito Justin Bieber Lyrics
Unit 11 Homework 3 Area Of Composite Figures
Canonnier Beachcomber Golf Resort & Spa (Pointe aux Canonniers): Alle Infos zum Hotel
Myapps Tesla Ultipro Sign In
ESPN's New Standalone Streaming Service Will Be Available Through Disney+ In 2025
Ingersoll Greenwood Funeral Home Obituaries
Latest Posts
Article information

Author: Trent Wehner

Last Updated:

Views: 6298

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Trent Wehner

Birthday: 1993-03-14

Address: 872 Kevin Squares, New Codyville, AK 01785-0416

Phone: +18698800304764

Job: Senior Farming Developer

Hobby: Paintball, Calligraphy, Hunting, Flying disc, Lapidary, Rafting, Inline skating

Introduction: My name is Trent Wehner, I am a talented, brainy, zealous, light, funny, gleaming, attractive person who loves writing and wants to share my knowledge and understanding with you.