react-pdf

使用React创建PDF文件。(Create PDF files using React.)

  • 所有者: diegomura/react-pdf
  • 平台: Linux, Mac, Windows, BSD, Cross-platform, Solaris, Unix-like
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

用于在浏览器、移动设备和服务器上创建PDF文件的React渲染器。

如何安装

 yarn add @react-pdf/renderer

工作原理

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. 在DOM中呈现

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

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

Node. 保存在文件中

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

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

Native. 在手机中呈现

即将推出

示例

对于每个示例,请尝试打开 output.pdf 以查看结果。

要运行这些示例,首先克隆该项目并安装依赖项:

git clone https://github.com/diegomura/react-pdf.git
cd react-pdf
yarn install

然后,运行 yarn example - &lt; example-name&gt;

 yarn example -- fractals

贡献者

这个项目的存在要感谢所有贡献的人。 [贡献]

赞助商

感谢所有赞助商![成为sponsors](https://opencollective.com/react-pdf#sponsors)

支持者

谢谢你们所有的支持者! [成为支持者](https://opencollective.com/react-pdf#backer)

许可证

麻省理工学院© Diego Muracciole

概覽

名稱與所有者diegomura/react-pdf
主編程語言JavaScript
編程語言JavaScript (語言數: 3)
平台Linux, Mac, Windows, BSD, Cross-platform, Solaris, Unix-like
許可證MIT License
發布數642
最新版本名稱@react-pdf/svgkit@2.3.9 (發布於 2024-03-27 08:56:39)
第一版名稱v0.2.0 (發布於 2017-06-21 23:12:36)
創建於2016-10-18 21:33:58
推送於2024-04-15 11:10:04
最后一次提交2024-03-27 09:54:05
星數14.1k
關注者數101
派生數1.1k
提交數1k
已啟用問題?
問題數1709
打開的問題數433
拉請求數622
打開的拉請求數26
關閉的拉請求數147
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

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

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

To run the examples, first clone the project and install the dependencies:

git clone https://github.com/diegomura/react-pdf.git
cd react-pdf
yarn install

Then, run yarn example -- <example-name>

yarn example -- fractals

Contributors

This project exists thanks to all the people who contribute. (CONTRIBUTING.md).

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


去到頂部