0.0.3 • Published 3 years ago

jsx-to-pdf v0.0.3

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

jsx-to-pdf Maintainability

A Simple Utility to render React JSX to PDF

Getting Started

Installation

$ npm i jsx-to-pdf

Basic Implementation

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

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

NameTypeDefaultDescription
nameStringjsxToPdfName of the PDF to be saved
scaleNumber1Scale of the HTMLNodeElement element
xNumber0Offset x of the PDF
yNumber0Offset y of the PDF
widthNumberJSPDF document widthWidth of the HTMLNodeElement to be set in PDF
heightNumberJSPDF document heightHeight of the HTMLNodeElement to be set in PDF
{...rest}Object{}JSPDF options

Output

Render Props

NameTypeDefaultDescription
saveFunction() => {}Trigger PDF Submit
jsxRefrefundefinedReference to the HTMLNodeElement
loadingBooleanfalseLoader for PDF save
errorBooleanfalseError
errorTextString() => {}Error Text

Hooks

NameTypeDefaultDescription
convertToPDFFunction() => {}Trigger PDF Submit
jsxRefrefundefinedReference to the HTMLNodeElement
loadingBooleanfalseLoader for PDF save
errorBooleanfalseError
errorTextString() => {}Error Text

Contribution

Questions

Feel free to contact me or create an issue