343
Views
8
Comments
[pdfJS Viewer Reactive] Preview a PDF that is stored in the database
pdfjs-viewer-reactive
Reactive icon
Forge asset by Eduardo Jauch
Application Type
Reactive

I am trying to display in a screen a pdf that is stored in a db table.

I tried to pass the url of a REST that returns the pdf content as a binary but didn't work. Is there a way of achieve what i want?

2025-01-07 17-06-54
Paulo Cação
Champion

Hi André,

You can preview a PDF file in react apps using an iframe:

For this, you need to convert your binary to Base64 using this function:


Regards,

Paulo


2019-05-20 14-36-54
André Caldeira

@Paulo CaĂ§Ă£o I did that and now i'm getting this error:

414 Request-URI Too Large

2025-01-07 17-06-54
Paulo Cação
Champion
2019-05-20 14-36-54
André Caldeira

No I can't.

Basically what i am doing is using a data action to get the binary and converting it to base64 and then pass it to the iframe. 

2025-01-07 17-06-54
Paulo Cação
Champion
2019-05-20 14-36-54
André Caldeira

I did this but continues without working. Shows the same error...

UserImage.jpg
Sarah Javed

did u get the solution for this.can u share oml

2019-09-23 12-14-09
Miguel Vicente

Hi there, I now that 2 years passed, but I've implemented this component with binary option.

Using JS I create a Blob and create a URL for it, feeding the component. Code bellow:

var byteCharacters = atob($parameters.Base64);

var byteNumbers = new Array(byteCharacters.length);

for (var i = 0; i < byteCharacters.length; i++) {  

byteNumbers[i] = byteCharacters.charCodeAt(i);}

var byteArray = new Uint8Array(byteNumbers);

var file = new Blob([byteArray], { type: 'application/pdf;base64' });

$parameters.NewURL =  URL.createObjectURL(file);

That code is placed on the top of the OnInitialize with a assign right after it, setting the JS Output to the existing URL input parameter (I've converted it to local variable).

Hope it helps

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.