Skip to content

ptzagk/react-pdf

 
 

Repository files navigation

react-pdf

React renderer for creating PDF files on the browser, mobile and server

How it works

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

// 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>
);

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

Render in DOM

import React from 'react';
import ReactDOM from 'react-dom';

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

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

Save in a file

import ReactPDF from 'react-pdf-node';

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

Render in mobile

Coming soon

Examples

For each example, try opening output.pdf to see the result.


Page Layout

Fractals

To run an example for yourself, run yarn example -- <example-name> locally.

Comments

This project was created to show some concepts on a talk, and it's purely experimental. You can check out the slides of the talk here

License

MIT © Diego Muracciole

About

Create PDF files using React

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%