ruki-react-pdf-creator
v1.0.5
Published
Create a pdf with only JSON values, create configurable fields and add custom values to you PDF fi
Downloads
3
Readme
ruki-react-pdf-creator
Create a pdf with only JSON values, create configurable fields and add custom values to you PDF fi
Install
npm install --save ruki-react-pdf-creator
Create PDF Templates
You can create templates here that can be exported as a JSONhere
New Update
- Introduced variable support for images and text components
Usage
import { useEffect, useState } from "react";
import { createPDF, PDFJSONParser } from "ruki-react-pdf-creator";
import template from "./invoice-template";//ADD JSON TEMPLATE FILE
export default function App() {
const [loading, setLoading] = useState(false);
const handleCreateInvoice = async () => {
setLoading(true);
const { components, pageSettings } = await PDFJSONParser(template);
const { pdfUrl, pdfBlob, pdfBytes } = await createPDF({
components,
pageSetting: pageSettings,
});
const href = URL.createObjectURL(pdfBlob);
const link = document.createElement("a");
link.href = href;
console.log(href);
link.download = `pdf-components(${new Date().toLocaleString()}).pdf`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
console.log(pdfUrl);
setLoading(false);
};
return (
<div className="App">
<h1>PDF Creator</h1>
<button onClick={handleCreateInvoice}>
{loading ? "Loading" : "Create Invoice"}
</button>
</div>
);
}
License
MIT © Ruki