Display PDF in reactJS

后端 未结 5 1027
渐次进展
渐次进展 2020-12-06 19:49

I am following this package https://www.npmjs.com/package/react-pdf

I got the entire raw pdf data from backend so I was trying with code below.



        
5条回答
  •  -上瘾入骨i
    2020-12-06 20:03

    I solved the problem. I convert the binary data that I received from backend into ArrayBuffer.

    axios.post(//fire your API).then(response =>
            (response.status === 200? response.data : null))
        .then(pdfdata => {
            var len = pdfdata.length;
            var bytes = new Uint8Array( len );
            for (var i = 0; i < len; i++){
                bytes[i] = pdfdata.charCodeAt(i);
            }
    
            const renderPdf = bytes.buffer
    

    Then I actually assign bytes.buffer to renderPDF to perform the rendering. Now it is working flawlessly!

    In rendering html from react,

    import PDF from 'react-pdf-scroll'
    
    

提交回复
热议问题