Untitled
unknown
plain_text
2 years ago
922 B
12
Indexable
const [pdfUrl, setPdfUrl] = useState("");
const handleGeneratePdf = async () => {
try {
const response = await axios.post(
"http://localhost:3000/v1/api/orders-pdf",
{
orderId: "657c2ca30c99005d1404a55f", // Replace with the actual order ID
},
{
headers: {
"Content-Type": "application/json",
},
responseType: "blob",
}
);
const blob = new Blob([response.data], { type: "application/pdf" });
const pdfUrl = URL.createObjectURL(blob);
setPdfUrl(pdfUrl);
} catch (error) {
console.error("Error generating PDF:", error);
}
};
return (
<div>
<button onClick={handleGeneratePdf}>Generate PDF</button>
{pdfUrl && (
<div>
<embed src={pdfUrl} width="800px" height="600px" />
</div>
)}
</div>
);Editor is loading...
Leave a Comment