0

I have the following text that i get from java with a get request. GET: http://localhost:8101/raportet/Cinema.jasper

%PDF-1.4
%âãÏÓ
3 0 obj
<</Filter/FlateDecode/Length 1644>>stream
xœ½œ]SÛF†ïý+ö2½ˆ²_úêUÝ`Rh;étz¡`aDü‘H†ß•Ç
8ïJø5ã³ ôé<^Yþ<ø}20‘ˆÃHL¦ƒÑdð×@‹ãê·JH÷¨¾Ç©“ÅàÕ¡JŠÉåàÅ 
..............

I want to download this file in frontend using js. I tried a lot of methods but i cannot download it. Is there any method i can do it. I've almost the same problem as this: Opening PDF String in new window with javascript

Lirzae
  • 66
  • 8

1 Answers1

0

you can use this method if you want to show and download PDF in ReactJs

 axios.get(exportUrl, {responseType:'blob'})
        .then(response => {
            // Create blob link to download
            var blob = new Blob([response.data], { type: 'application/pdf' });

            var URL = window.URL || window.webkitURL;
            const url = window.URL.createObjectURL(blob);
            const link = document.createElement('a');
            link.target   = '_blank';
            link.href = url;
            link.setAttribute(    //if you just want to preview pdf and dont want download delete this three lines 
               'download',
               `Factor.pdf`,
             );
        
            // Append to html link element page
            document.body.appendChild(link);
        
            // Start download
            link.click();
        
            // Clean up and remove the link
            link.parentNode.removeChild(link);
            URL.revokeObjectURL(url);

        })
    }