Hi @wojtekmaj, community,
Thanks for building and maintaining this lib !
While using the module, I have come across a UI where I need to show all pages of the pdf in a scrollable fashion. Currently what I do is along the lines of :
[1...this.state.totalPages] and render <ReactPDF ... /> with relevant page number. Here's what the map code looks like :
{(Array.from({length: this.state.totalPages}, (v, k) => k+1)).map((i) => {
console.log(i)
return (
<div className='w-100 center tc mt3' key={i}>
<ReactPDF
width={screen.width*0.6}
file={'http://localhost:5000/assets/dance.pdf'}
pageIndex={i}
loading={this.renderLoader()}
/>
</div>
);
})}
This works, but sends out multiple requests (number of pages + 1) to the resource file. This leads to poor experience as the load time is too much.
Is there a cleaner solution for this ?
Thanks.
I was able to solve this is the following way :
{pdf: null, initialised: false, totalPages: null}Thanks.
Hey! @shivekkhurana! Just so you know, newest v2.0.0 (alpha) supports multiple pages within one <Document /> component - no need for weird workarounds! :) Let me know what you think!
Wait, but do you have to know how many pages there are or is there a way to just display all that are there?
You have to know. And you do know from Document's onLoadSuccess, check Sample.jsx for one of many possible implementations.
Most helpful comment
Hey! @shivekkhurana! Just so you know, newest v2.0.0 (alpha) supports multiple pages within one
<Document />component - no need for weird workarounds! :) Let me know what you think!