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

I can't center the pages of my pdf #874

Open
juan-andres-valverde-endava opened this issue Oct 7, 2024 · 4 comments
Open

I can't center the pages of my pdf #874

juan-andres-valverde-endava opened this issue Oct 7, 2024 · 4 comments

Comments

@juan-andres-valverde-endava
Copy link

juan-andres-valverde-endava commented Oct 7, 2024

What react-native version are you using?
0.75.0
What react-native-pdf version are you using?
I have tried with the same behaviour in 6.7.5, 6.7.4, 6.6.2

What platform does your issue occur on?
Android

Describe your issue as precisely as possible :
I am having a problem when displaying a pdf within my application, when the pdf has more than 2 pages the intermediate pages, which are neither the first nor the last, are always displayed on the left edge of the container.
JustifyContent center does not solve the problem. I think that it is simply the behavior of the library, when activating the horizontal together with the enablePaging.

It works perfectly on IOS this error only occurs on Android.

Any thoughts, solutions, different approach?

Join a screenshot or video of the problem on the simulator or device?

This is how its supposed to should work, and how it does work in the first and last page

Screenshot 2024-10-07 at 1 11 19 PM

And this is the error and how it does works in the intermediate pages

Screenshot 2024-10-07 at 1 19 04 PM

Show us the code you are using?

<View
        style={styles.pdfContainer}
        testID={LoanProposalDisclosureIds.pdfContainer}>
        {!!pdfFile && (
          <Pdf
            source={{ uri: `data:application/pdf;base64,${pdfFile}` }}
            style={{ flex: 1, paddingVertical: 8 }}
            horizontal={true}
            enablePaging={true}
            page={currentPage}
            onPageChanged={page => {
              setCurrentPage(page);
              page === totalPages && setFullyRead(true);
            }}
            onLoadProgress={() => {
              setIsPdfLoading(true);
            }}
            onLoadComplete={numberofPages => {
              setTotalPages(numberofPages);
              setIsPdfLoading(false);
              numberofPages === 1 && setFullyRead(true);
            }}
            onError={error => {
              showDialog(toDialogError(error, appLanguage));
              setIsPdfLoading(false);
            }}
          />
        )}
      </View>
     ```

@rajivchaulagain
Copy link

rajivchaulagain commented Oct 22, 2024

  <Pdf
          ref={pdfRef}
          trustAllCerts={false}
          source={{
            uri,
          }}
          onLoadProgress={(percent) => calculateLoadingProgress(percent)}
          style={{
            width,
            height,
          }}
          onPageSingleTap={(e, x, y) => handlePosition(e, x, y)}
          onLoadComplete={(numberOfPages, path, { height, width }) =>
            console.log(`height & width : ${height} ${width}`)
          }
        />
        
    provide width and height as below its all about custom styling of pdf
      const { width, height } = Dimensions.get("window");

@joffblack
Copy link

joffblack commented Oct 23, 2024

I have a very similar issue to @juan-andres-valverde-endava. My first and last pages work well. But my middle pages are aligned to the top of the screen, rather than in the centre.

This is only on Android, iOS is working perfectly.

When i console.log the width and height after onLoadComplete, i am getting the same width and height regardless of what page i am on.

Thanks @rajivchaulagain - any other ideas?

@rajivchaulagain
Copy link

rajivchaulagain commented Oct 23, 2024

@joffblack I think this package only sees all the pages of pdf as a single height and width so managing the height and width of individual is hard so, could you try using this code

const pageStyles = (page, numberOfPages) => ({
  flex: 1,
  justifyContent: 'center',
  alignItems: page === 1 || page === numberOfPages ? 'flex-start' : 'center',
});
onPageChanged={(page, numberOfPages) => {
   setPageStyle(pageStyles(page, numberOfPages)); 
 }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@joffblack @rajivchaulagain @juan-andres-valverde-endava and others