Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing all pages at once #27

Closed
shivekkhurana opened this issue Apr 6, 2017 · 4 comments
Closed

Showing all pages at once #27

shivekkhurana opened this issue Apr 6, 2017 · 4 comments
Assignees
Labels
enhancement New feature or request question Further information is requested
Milestone

Comments

@shivekkhurana
Copy link

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. Create a hidden div, load first page, save total number of pages to state.
  2. Map from [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.

@shivekkhurana
Copy link
Author

I was able to solve this is the following way :

  1. Initialise component state with {pdf: null, initialised: false, totalPages: null}
  2. Load pdf file using xhr and save it to state.
  3. Have a component which renders only if pdf is not null and initialises by reading the pdf and setting initialised to true and totalPages. This div is inside a hidden container.
  4. Map over 0 to totalPages if totalPages !== null and render each page using the pdf in state

Thanks.

@wojtekmaj
Copy link
Owner

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!

@wojtekmaj wojtekmaj added enhancement New feature or request question Further information is requested labels Jul 16, 2017
@wojtekmaj wojtekmaj self-assigned this Jul 16, 2017
@wojtekmaj wojtekmaj added this to the 2.0.0 milestone Jul 16, 2017
@geoguide
Copy link

geoguide commented May 5, 2018

Wait, but do you have to know how many pages there are or is there a way to just display all that are there?

@wojtekmaj
Copy link
Owner

You have to know. And you do know from Document's onLoadSuccess, check Sample.jsx for one of many possible implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants