dynamically load pdf file
Answered
Arthur posted this in #help-forum
ArthurOP
I am trying to use
react-pdf
to load a pdf file from an api request.Answered by Arthur
Minor detail: Forgot to add
data:application/pdf;base64,
but added it now (still no change)15 Replies
I can't use
Uint8Array
because nextjs doesnt allow you to pass Uint8Array
from server to clientthen I reconvert the base64 to a buffer array but it wont show the pdf file
keeps saying this
ArthurOP
Minor detail: Forgot to add
data:application/pdf;base64,
but added it now (still no change)Answer
ArthurOP
not actually the answer but got it working
If I may, this exactly a use case for route handler
where is fetchInvoicePdf used?
in your setup I find it a bit weird to download the PDF from the source from the clienty
it's harder to secure because you have to make your invoice api endpoint public
you could have a Route Handler that downloads the PDF from your 3rd party API, and call this route handler from your React component
=> this gives you more control over the format, security etc. because you handle the "hard" part server-side
and then client-side you just do a simple call
anyway if you have smth that works it's cool