@david.kucsai/react-pdf-table

中文文档
0.4.1发布于 2022/02/12MITTypeScriptCommonJS零依赖近 30 天下载 1.7万

Provides tables for the @react-pdf/renderer.

原始使用文档
文档目录4 节
  1. Documentation
  2. Notes
  3. Examples
  4. Running Locally

@david.kucsai/react-pdf-table

This library is designed to be used with @react-pdf/renderer.

The goal behind this library is to provide a declarative way of defining tables in a PDF.

npm version

To get started run:

 npm install "@david.kucsai/react-pdf-table"

On Windows you must escape the '.':

npm install "@david`.kucsai/react-pdf-table"

Documentation

Refer to API Documentation for the type definitions.

Notes

  • Layout uses flex behind the scenes.
  • If weighting is not defined for a table cell then it will default to the remaining unassigned weightings.
    • weighting should be between 0..1. Preferably adding up to <= 1.
  • If you have lots of rows to display it's recommended to batch up the rows and render them on separate pages to ensure that values are not cut off.
  • Content in TableCell and DataTableCell must either evaluate to a string or a @react-pdf/renderer component e.g. View, Text etc. If the content is a string it will be wrapped with a Text element.
  • TableCells and DataTableCells can override a lot of the configuration passed to them.

Examples

Simple Example

This example will render a header and one row using the default styling.

<PDFViewer>
    <Document>
        <Page>
            <Table
                data={[
                    {firstName: "John", lastName: "Smith", dob: new Date(2000, 1, 1), country: "Australia", phoneNumber: "xxx-0000-0000"}
                ]}
            >
                <TableHeader>
                    <TableCell>
                        First Name
                    </TableCell>
                    <TableCell>
                        Last Name
                    </TableCell>
                    <TableCell>
                        DOB
                    </TableCell>
                    <TableCell>
                        Country
                    </TableCell>
                    <TableCell>
                        Phone Number
                    </TableCell>
                </TableHeader>
                <TableBody>
                    <DataTableCell getContent={(r) => r.firstName}/>
                    <DataTableCell getContent={(r) => r.lastName}/>
                    <DataTableCell getContent={(r) => r.dob.toLocaleString()}/>
                    <DataTableCell getContent={(r) => r.country}/>
                    <DataTableCell getContent={(r) => r.phoneNumber}/>
                </TableBody>
            </Table>
        </Page>
    </Document>
</PDFViewer>

Formatting Example - Aligning Text and Weightings for columns

This example will render a header and one row using the default styling.

<PDFViewer>
    <Document>
        <Page>
            <Table
                data={[
                    {firstName: "John", lastName: "Smith", dob: new Date(2000, 1, 1), country: "Australia", phoneNumber: "xxx-0000-0000"}
                ]}
            >
                <TableHeader textAlign={"center"}>
                    <TableCell weighting={0.3}>
                        First Name
                    </TableCell>
                    <TableCell weighting={0.3}>
                        Last Name
                    </TableCell>
                    <TableCell>
                        DOB
                    </TableCell>
                    <TableCell>
                        Country
                    </TableCell>
                    <TableCell>
                        Phone Number
                    </TableCell>
                </TableHeader>
                <TableBody>
                    <DataTableCell weighting={0.3} getContent={(r) => r.firstName}/>
                    <DataTableCell weighting={0.3} getContent={(r) => r.lastName}/>
                    <DataTableCell getContent={(r) => r.dob.toLocaleString()}/>
                    <DataTableCell getContent={(r) => r.country}/>
                    <DataTableCell getContent={(r) => r.phoneNumber}/>
                </TableBody>
            </Table>
        </Page>
    </Document>
</PDFViewer>

Running Locally

To run the storybook:

yarn storybook

Compile to typescript:

yarn recompile

Build (Clean & Compile):

yarn build

Run tests:

yarn test

版本与发布记录

@david.kucsai/react-pdf-table 共发布 8 个版本,首次发布于 2019/06/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.4.1latest2022/02/124 年前
0.4.02022/02/124 年前
0.3.02020/02/056 年前
0.2.02020/02/056 年前
0.1.12019/08/117 年前
0.1.02019/06/297 年前

关于 @david.kucsai/react-pdf-table 的常见问题

@david.kucsai/react-pdf-table 是什么?

Provides tables for the @react-pdf/renderer.

如何安装 @david.kucsai/react-pdf-table?

在项目目录运行 npm install @david.kucsai/react-pdf-table,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@react-pdf/renderer(^1.6.8)、react(^16.8.6)、react-dom(^16.8.6)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@david.kucsai/react-pdf-table 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@david.kucsai/react-pdf-table 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@david.kucsai/react-pdf-table 可以商用吗?

@david.kucsai/react-pdf-table 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@david.kucsai/react-pdf-table 的下载量有多少?

根据 npm 官方下载统计,@david.kucsai/react-pdf-table 在 2026/10/12 – 2026/11/10 这 30 天内被下载 16,542 次,日均约 551 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@david.kucsai/react-pdf-table 还在维护吗?

最新版本 0.4.1 发布于 2022/02/12(4 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/06/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。