# jsx-to-pdf

> A Simple Utility to render React JSX to PDF

Latest version **0.0.3** (published 2021-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install jsx-to-pdf
pnpm add jsx-to-pdf
yarn add jsx-to-pdf
bun add jsx-to-pdf
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2021-01-03 |
| First published | 2020-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 29.2 KB |
| Known vulnerabilities | 0 (+12 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Pritish Vaidya |
| Maintainers | pritishvaidya |

## Links

- npm: https://www.npmjs.com/package/jsx-to-pdf
- Repository: https://github.com/pritishvaidya/jsx-to-pdf
- Homepage: https://github.com/pritishvaidya/jsx-to-pdf#readme
- Issues: https://github.com/pritishvaidya/jsx-to-pdf/issues
- npm.io page: https://npm.io/package/jsx-to-pdf

## Dependencies (2)

- [jspdf](https://npm.io/package/jspdf.md) ^2.2.0
- [dom-to-image](https://npm.io/package/dom-to-image.md) ^2.6.0

## Recent versions

- 0.0.3 (latest) — 2021-01-03
- 0.0.1 — 2020-12-27

## README

# jsx-to-pdf [![Maintainability](https://api.codeclimate.com/v1/badges/7423dd108f497de225d5/maintainability)](https://codeclimate.com/github/pritishvaidya/jsx-to-pdf/maintainability)
A Simple Utility to render React JSX to PDF

## Getting Started

- [Installation](#installation)
- [Basic Implementation](#basic-implementation)
- [Hook Implementation](#hook-implementation)
- [Output](#output)
- [Contribution](#contribution)
- [Questions](#questions)

### Installation

```bash
$ npm i jsx-to-pdf
```

### Basic Implementation

```jsx
import { JsxToPdf } from "jsx-to-pdf";

function App() {
  return (
    <JsxToPdf>
        {({ save, jsxRef, error, errorText }) => {
          return (
            <div className="App" ref={jsxRef}>
              <button style={{ height: 50, margin: 20, backgroundColor: '#61dafb' }} onClick={save}>Download PDF for this Page</button>
            </div>
          )
        }}
    </JsxToPdf>
  )
}
```

### Hook Implementation

```jsx
import { useJsxToPdf } from "jsx-to-pdf";

function App() {
  const { jsxRef, convertToPdf } = useJsxToPdf()
  return (
    <div className="App" ref={jsxRef}>
      <button style={{ height: 50, margin: 20, backgroundColor: '#61dafb' }} onClick={save}>Download PDF for this Page</button>
    </div>
  )
}
```

### Input
| Name  | Type  | Default | Description |
| :------------ |---------------:| :---------------| :-----|
| name | String | `jsxToPdf` | Name of the PDF to be saved |
| scale | Number | 1 | Scale of the HTMLNodeElement element  |
| x | Number | 0 | Offset x of the PDF |
| y | Number | 0 | Offset y of the PDF |
| width | Number | JSPDF document width | Width of the HTMLNodeElement to be set in PDF |
| height | Number | JSPDF document height | Height of the HTMLNodeElement to be set in PDF |
| {...rest} | Object | `{}` | [JSPDF](http://raw.githack.com/MrRio/jsPDF/master/docs/jsPDF.html) options  |


### Output

#### Render Props
| Name  | Type  | Default | Description |
| :------------ |---------------:| :---------------| :-----|
| save | Function | `() => {}` | Trigger PDF Submit |
| jsxRef | `ref` | undefined | Reference to the HTMLNodeElement  |
| loading | Boolean | false | Loader for PDF save |
| error | Boolean | false | Error |
| errorText | String | `() => {}` | Error Text |

#### Hooks
| Name  | Type  | Default | Description |
| :------------ |---------------:| :---------------| :-----|
| convertToPDF | Function | `() => {}` | Trigger PDF Submit |
| jsxRef | `ref` | undefined | Reference to the HTMLNodeElement  |
| loading | Boolean | false | Loader for PDF save |
| error | Boolean | false | Error |
| errorText | String | `() => {}` | Error Text |


## Contribution

- [@pritishvaidya](mailto:contact@pritishvaidya.dev) The main author.

## Questions

Feel free to [contact me](mailto:contact@pritishvaidya.dev) or [create an issue](https://github.com/pritishvaidya/jsx-to-pdf/issues/new)

---
_Source: https://npm.io/package/jsx-to-pdf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
