diegomura / diegomura/react-pdf

Ability to determine pages a fixed element shows up on

Open
#631 0 comments 1 reaction 0 assignees View on GitHub
new feature
Dominant language
TypeScript
Stars
16.8k
Forks
1.3k
Avg merge
5h 6m
Merged PRs (30d)
52

Description

**Is your feature request related to a problem? Please describe.**
I would like to dynamically render the following layout:
[document.pdf](https://github.com/diegomura/react-pdf/files/3263788/document.pdf)

namely, the ability to dynamically render "page x of y" where x is the current iteration of the fixed element, and y is the total number of rendered fixed elements. I can't hard code these values since the pdf content is generated dynamically.

**Describe the solution you'd like**
I would like to be able to accomplish the above using something similar to Text's `render` prop. Something like:

```jsx
`page ${currentElement} of ${totalElements}`}
```

**Describe alternatives you've considered**
I assumed I would be able to keep track of which pages an element shows up on using the existing `render` prop on text:

```jsx
class SectionText extends React.Component {
appearsOnPage = new Set()

render() {
return {
const appearsOnPagesArray = Array.from(this.appearsOnPages)
const totalElements = appearsOnPagesArray.length
const firstPage = Math.min(...appearsOnPagesArray)
const currentElement = pageNumber - firstPage + 1

return `Page ${currentElement} of ${totalElements}`
}} />
}
}
```

However, it appears `render` is called on Text for _all_ pages, not just the one where Text is actually rendered.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.