Next.js Discord

Discord Forum

dynamically load pdf file

Answered
Arthur posted this in #help-forum
Open in Discord
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)
View full answer

15 Replies

Currently I have this
I can't use Uint8Array because nextjs doesnt allow you to pass Uint8Array from server to client
then I reconvert the base64 to a buffer array but it wont show the pdf file
keeps saying this
Minor detail: Forgot to add data:application/pdf;base64, but added it now (still no change)
Answer
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