I want to download pdf from the api response directly and currently i am using js-file-download package. I am currently getting empty pdf by using this. Below is my code.
const fileDownload = require("js-file-download");
const handleDownloadPdf = async () => {
console.log(statusData);
try {
return api(
`my_api_url`,
{},
"get"
).then((apiCall) => {
console.log(apiCall);
fileDownload(apiCall.data, "InvoiceSearchExport.pdf");
});
} catch (err) {
console.log({ Error: err });
}
};
<Menu.Item onClick={() => handleDownloadPdf()} key="3">
Download
</Menu.Item>
This is what i am geting from my api response inside apiCall.data.
%PDF-1.7 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R ] /Count 1 /Resources << /ProcSet 4 0 R /Font << /F1 8 0 R /F2 9 0 R
/XObject << /I1 10 0 R /I2 11 0 R
/MediaBox [0.000 0.000 595.280 841.890] endobj 4 0 obj [/PDF /Text /ImageC ] endobj 5 0 obj << /Producer (�� Can someone please help me with this!