question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

page-wrapping does not provide totalPages

See original GitHub issue

Describe the bug When using render prop on Text, the totalPages value is not provided until the second pass.

This would usually be fine (and is appropriately called out in the docs to watch out for), however, if the fixed prop is not defined on Text then render is only called once and 1/undefined gets rendered to the page.

Looks like the second pass render is deliberately skipped if fixed is not supplied. Assuming as a performance optimization. But it seems maybe this is not a valid optimization that can be made.

To Reproduce Steps to reproduce the behavior including code snippet (if applies):

<Document>
  <Page>
    <Text render={({ totalPages }) => /* totalPages is undefined */} />
</Document>

Expected behavior Either totalPages should be defined on the first pass, or render should always be called twice.

Screenshots

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: N/A (node)
  • React-pdf version: 1.1.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
superveetzcommented, Aug 5, 2020

For anyone running into this problem still, I found this work around:

`

        <View
          fixed={true}
          style={styles.footer}
          render={(props) => {
            console.log('props:', props)
            return (
              <View>
                <Text style={styles.hidden}>{JSON.stringify(props)}</Text>
                <Text
                  style={styles.footerPageNumber}
                  render={(textProps) => {
                    return (
                      <Text>
                        Page {textProps?.pageNumber?.toString()} of{' '}
                        {textProps?.totalPages?.toString()}
                      </Text>
                    )
                  }}
                />
              </View>
            )
          }}
        />

    const styles = StyleSheet.create({
    ...,
    hidden: {
        display: 'none',
        color: styleVars.white,
    },
    ...
})

` This line is required <Text style={styles.hidden}>{JSON.stringify(props)}</Text> … not sure why I keep finding these hacks where rendering props and hiding it causes the component props to be as expected. (Ran into this with react-hook-form library also). In this case, display: none doesn’t seem to work, so I blended the stringified props text into the background by changing it to white.

2reactions
diegomuracommented, Feb 2, 2019

Thanks for reporting this @arahansen

To be honest I don’t remember very well why I as forcing render to be called just once on non-fixed elements. It could be a performance optimization 🤔

Anyways, it does not make much sense now, so I’m removing that check. Unfortunately making render to be called just one time would involve a bit much of effort, and I’m not sure even if would be possible, so the only way of fixing this now is by just removing that line 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pagination issue: returning total count and total pages in body ...
I think, the better solution would be to actually wrap all those answers + summary details in separate object, that holds them all...
Read more >
error calling TotalPages: runtime error: invalid memory ...
Like I said above, the error message implies that you are trying to access a nil value. So wrap your code in a...
Read more >
Problem Retrieving the Total Pages in a Print Job — oracle-tech
In order to get the total number of pages, I have to call the print(Graphics g, PageFormat pageFormat,int pageIndex) method. Inside that method...
Read more >
Word wrap & Can grow causing report pages not same in ...
First, Stimulsoft Report (.mrt) databand field (example address) set to "no word wrap" and "no can grow" the report preview show total pages...
Read more >
Total pages are not displayed in mobile devices | WordPress.org
That is odd, kindly share the snapshot of the section where you have added this code. Thread Starter skraven. (@skraven).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found