Hi Friends,
Can anyone please give the ways to move further steps.
I am trying to download a server side generated pdf file in client, which i get with axios and save it in redux and using FileSaver to download it.
const getTicketPdf = ({ userID, ticketID }) =>
requestApi(/users/${userID}/tickets/${ticketID}/pdf
, {
method: 'get',
});
requestApi gets me all neccessary headers so that i can download the file.
the data is then stored in redux like this:
data: "%PDF-1.4\n3 0 obj\n<>\nendobj\n4 0 obj\n<>\nstream\nx�3R��2�35W(�*T0P�R0T(\u0007�Y@�\u000e��@Q…"
I call it in render with:
this.getPdf(ticket) }>PDF
getPdf = ticket => {
const blob = new Blob([ticket]);
FileSaver.saveAs(blob, 'Ticket.pdf');
}
I am always getting the following error:
TypeError: Cannot read property 'saveAs' of undefined
i tried also to set
responseType: 'blob'
but this doesn't help either.
Next thing I testet was with react-pdf library, where I managed to display pdf in Component, but i cant print it. User should only habe to save it and then print it locally (or at least show it in separate tab as PDF, which i tried with window.open() as base64 encoded string).
How can I download a server side generated PDF otherwise? Are there any better ways?
Unfortunately, I have to set HTTP Headers in order to get that file.
How might I do this?
Thanks in Advance.