Multi Page PDF is not showing, react-pdf

57 views Asked by At

I successfully converted a blob into a URL for a single-page PDF, and everything seems to be functioning correctly. However, when dealing with a multi-page PDF, the content inside the pages is not displaying as expected.

 // Component states
              const [fileUrl, setFileUrl] = useState(false);
              const [numPages, setNumPages] = useState(1);
              const [pageNumber, setPageNumber] = useState(1);
            
              React.useEffect(() => {
               // Getting blob converting to URL
                      const blob = new Blob([response], { type: "application/pdf" });
                      const pdfUrl = URL.createObjectURL(blob);
                      setFileUrl(pdfUrl);
                }
                
              }, []);
            
            
            // On document load
              const onDocumentLoadSuccess = ({ numPages }) => {
                setNumPages(numPages);
              };
               
        // document pages 
              const pages = [];
              for (let i = 1; i <= numPages; i++) {
                pages.push(
                  <Page
                    key={i}
                    pageNumber={i}
                    scale={scale}
                  />
                );
              }
            // document
            {fileUrl && (
                    <div className="document" style={documentStyle}>
                      <Document
                        file={fileUrl}
                        onLoadSuccess={onDocumentLoadSuccess}
                      
                      >
                        {pages}
                      </Document>
                    </div>
                  )}
0

There are 0 answers