Skip to content

davidlee0602/react-pdf

Β 
Β 

Repository files navigation

React renderer for creating PDF files on the browser and server

New react-pdf 2.0 was released. Read about the announcement

What can you create with react-pdf?

React-pdf is a package that allows you to create and render PDF documents through the use of React Components. Pages that can be rendered as a downloadable document. A wide variety of use cases can be supported with this project; enabling dynamic web pages to be saved statically in a widely accepted document format. Simply add the tool as a dependency in your React project and display away!

How to install

yarn add @react-pdf/renderer

How it works

import React from 'react';
import { Document, Page, Text, View, StyleSheet } from '@react-pdf/renderer';

// Create styles
const styles = StyleSheet.create({
  page: {
    flexDirection: 'row',
    backgroundColor: '#E4E4E4'
  },
  section: {
    margin: 10,
    padding: 10,
    flexGrow: 1
  }
});

// Create Document Component
const MyDocument = () => (
  <Document>
    <Page size="A4" style={styles.page}>
      <View style={styles.section}>
        <Text>Section #1</Text>
      </View>
      <View style={styles.section}>
        <Text>Section #2</Text>
      </View>
    </Page>
  </Document>
);

Web. Render in DOM

import React from 'react';
import ReactDOM from 'react-dom';
import { PDFViewer } from '@react-pdf/renderer';

const App = () => (
  <PDFViewer>
    <MyDocument />
  </PDFViewer>
);

ReactDOM.render(<App />, document.getElementById('root'));

Node. Save in a file

import React from 'react';
import ReactPDF from '@react-pdf/renderer';

ReactPDF.render(<MyDocument />, `${__dirname}/example.pdf`);

Examples

Render Abstract Images with Components


Sample Link PDF Path

Create Your Professional Resume


Sample Link PDF Path

Create Static Documents


Sample Link PDF Path

To check the source code and run the examples locally:

(Done via your OS terminal)
1. Clone this repository with your terminal: git clone https://github.com/diegomura/react-pdf
2. Navigate to sub-directory "/react-pdf/templates/"
3. Navigate to folder: Fractal, Resume or Document.
4. In the folder of the template to view, enter command in the terminal: npm install --legacy-peer-deps
5. After all dependencies are installed, type in terminal to run: npm start
6. Sample pages will be viewable through the browser @ http:https://localhost:3000/

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Sponsors

Thank you to all our sponsors! [Become a sponsors]

Backers

Thank you to all our backers! [Become a backer]

License

MIT Β© Diego Muracciole

FOSSA Status


About

πŸ“„ Create PDF files using React

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%