react-pdf

diegomuraMIT活跃维护

用 React 组件的方式生成 PDF 文件,把 JSX 直接渲染成排版好的 PDF,省去手写底层绘图代码。

📄 Create PDF files using React

@react-pdf/[email protected]发布于 2026-08-27 23:04 UTC16,854star +3 / 7 天1,346fork同步于 2026-11-10 05:24 UTC

怎么上手

从 README 代码块原样提取,可能是其中一种安装方式
yarn add @react-pdf/renderer
硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

5 个版本@react-pdf/[email protected]
  1. @react-pdf/[email protected]最新正式版2026-08-27 · 2026-08-27 23:04 UTC

    Minor Changes

    • #3537 77285e289dcaa588637d19b82461434763709728 Thanks @diegomura! - Add @react-pdf/ui, headless React primitives for building PDF preview and editor interfaces. Repl plus Files, Editor, Document, Pagination, Status, CopyButton and DownloadButton, each taking a Component prop so the library holds the behaviour and the consumer holds the markup. The render pipeline is injected, so the package depends on neither a compiler nor pdfjs-dist.

    Patch Changes

  2. @react-pdf/[email protected]2026-08-27 · 2026-08-27 23:04 UTC
    查看更新说明

    Minor Changes

    • #3536 9c2e5119ee47e3e92beede0a12870f1ebe3ecc8e Thanks @diegomura! - Add @react-pdf/tailwind, a Tailwind CSS to react-pdf style converter. Migrated from react-pdf-tailwind by Andreas Anckar, with the author's permission.

      On top of the original: breakpoint and orientation variants map onto react-pdf's media queries (lg:p-4, portrait:), colour opacity is supported wherever a colour is accepted (bg-red-500/50, text-black/25), and utilities were added for react-pdf style properties that had no Tailwind mapping — aspect-*, line-clamp-*, float-* / clear-*, skew-*, size-*, and the font-variant-numeric utilities. Anything react-pdf can't draw — state variants like hover:, lengths like w-fit, the default font-sans stacks — is reported as an unsupported class rather than emitted and crashing layout.

    Patch Changes

  3. @react-pdf/[email protected]2026-08-27 · 2026-08-27 23:04 UTC
    查看更新说明

    Minor Changes

    • #3531 b768f01e862cd56987f046c117919191ef810646 Thanks @diegomura! - Reintroduce @react-pdf/svgkit: a pdfkit-shaped drawing context that renders documents to SVG strings. @react-pdf/render gains an optional ctx.glyphs capability seam so non-PDF backends receive raw glyphs; pdf output is unchanged.
  4. @react-pdf/[email protected]2026-08-27 · 2026-08-27 22:57 UTC
    查看更新说明

    Patch Changes

  5. @react-pdf/[email protected]2026-08-27 · 2026-08-27 22:57 UTC
    查看更新说明

    Minor Changes

    • #3529 10d8365e2eb8fc3987cf94d4d61a7559f4ba1dfb Thanks @diegomura! - feat: add conformance Document prop for PDF/A output

      Produces PDF/A-1/2/3 (b-level) output with XMP conformance metadata and an sRGB OutputIntent. pdfVersion defaults to what the chosen level requires. Fonts must be registered (not the built-in standard 14) to fully validate.

    Patch Changes

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Lost?

    This package is used to create PDFs using React. If you wish to display existing PDFs, you may be looking for react-pdf.

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

    Contributors

    This project exists thanks to all the people who contribute. Looking to contribute? Please check our [contribute] document for more details about how to setup a development environment and submitting code.

    Sponsors

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

    Backers

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

    License

    MIT © Diego Muracciole