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

Links not clickable in the rendered pdf. #552

Closed
rishabhbatra10 opened this issue Apr 15, 2020 · 8 comments
Closed

Links not clickable in the rendered pdf. #552

rishabhbatra10 opened this issue Apr 15, 2020 · 8 comments
Assignees
Labels
question Further information is requested

Comments

@rishabhbatra10
Copy link

rishabhbatra10 commented Apr 15, 2020

I did read the previous issue #199 which had explained some of the possible reasons links are not working and hence I imported the AnnotationLayer.css. But still, I am facing this issue of links not being clickable.

Here is my code

import React, { Component } from 'react';
import { pdfjs, Document, Page } from "react-pdf";

import 'react-pdf/dist/Page/AnnotationLayer.css';
import './__style.css';

pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;

class Catalogue extends Component {
  constructor(props){
    super(props);
    this.state = { numPages: null, pageNumber: 1 };
  }

  onDocumentLoadSuccess = ({ numPages }) => {
    this.setState({ numPages });
  };

  goToPrevPage = () => {
    const { pageNumber } = this.state
    if (pageNumber !== 1) {
      this.setState(state => ({ pageNumber: state.pageNumber - 1 }));
    }
  }
  goToNextPage = () => { 
    const { pageNumber, numPages } = this.state
    if (pageNumber !== numPages) {
      this.setState(state => ({ pageNumber: state.pageNumber + 1 }));
    }
  }
  getPages = () => {
    const items = []
    let i = 1
    let { numPages } = this.state
    while (i <= numPages) {
      items.push(<Page pageNumber={i} key={i * Math.floor(Math.random() * 1000) + 1} style=""/>);
      i++;
    }  
    return items
  }

  render() {
    return (
      <div class="magazine">
        <div>
          <Document
            file={process.env.PUBLIC_URL + '/files/' + this.props.pdfFile}
            onLoadSuccess={this.onDocumentLoadSuccess}
          > 
            {this.getPages()}
          </Document>
        </div>
      </div>
    );
  }
}

export default Catalogue

Please let me know if I am missing out anything. Thanks!

Screenshot 2020-04-15 at 4 08 17 PM

Environment

  • React-PDF version [e.g. 3.0.4]: 4.1.0
  • React version [e.g. 16.3.0]: 16.12.0
@wojtekmaj
Copy link
Owner

wojtekmaj commented Apr 15, 2020

Anything in the console?

Try adding

onRenderAnnotationLayerSuccess={console.log}
onRenderAnnotationLayerError={console.error}
onGetAnnotationsError={console.error}

to your <Page /> component. Maybe it will tell us something. If not, we'll need to make an interactive codepen to see what the problem might be.

BTW:

key={i * Math.floor(Math.random() * 1000) + 1}

that's a horrible, horrible idea.

@wojtekmaj wojtekmaj self-assigned this Apr 15, 2020
@wojtekmaj wojtekmaj added the question Further information is requested label Apr 15, 2020
@rishabhbatra10
Copy link
Author

rishabhbatra10 commented Apr 15, 2020

Thank you for your reply @wojtekmaj. I added the event listeners but nothing is logged on any of the above listeners.
While onLoadSuccess logs this
Screenshot 2020-04-15 at 5 43 21 PM

Is there anything we should make sure to add in pdfs to make the links like this work?

Haha and that key thing I know was just playing around 😛

@wojtekmaj
Copy link
Owner

If neither onRenderAnnotationLayerSuccess nor onRenderAnnotationLayerError were called, then no annotations were loaded. Check is onGetAnnotationsSuccess callback returns something (it should).

Attach PDF file if it still fails.

@rishabhbatra10
Copy link
Author

onGetAnnotationsSuccess callback returns blank arrays, here is the pdf file.
pankhuri-issue_1-vol_1.pdf

@tjsudarsan
Copy link

tjsudarsan commented May 19, 2020

@rishabhbatra10 I too faced the same problem, but this is nothing to do with the @wojtekmaj's react-pdf library.

I just converted my pdf to word which has links that's not working and found that the hyperlinks are not added to those texts. So, I added the hyperlinks in the word documents and then converted to PDF, hosted it on my server again.

Now, it's working fine and I get the links in onGetAnnotationsSuccess callbacks too.

The problem is we got confused that the links without hyperlinks works both on Adobe Reader and also on the Chrome PDF Viewer. It seems, they detect the links that are not hyperlinked and hyperlink the same.

Provided that we should import the Annotation Layer css in our ReactApp

import 'react-pdf/dist/Page/AnnotationLayer.css';

@asharafshahi
Copy link

I'm on version 5.7.1 and import 'react-pdf/dist/Page/AnnotationLayer.css' doesn't work. I tried import 'react-pdf/dist/esm/Page/AnnotationLayer.css' but get this:
image

Any other options for getting links to actually work in the rendered PDF?

@ghost
Copy link

ghost commented Sep 26, 2022

I'm on version 5.7.1 and import 'react-pdf/dist/Page/AnnotationLayer.css' doesn't work. I tried import 'react-pdf/dist/esm/Page/AnnotationLayer.css' but get this: image

Any other options for getting links to actually work in the rendered PDF?

This import got it working for me.
import 'react-pdf/dist/esm/Page/AnnotationLayer.css';

@emmanuellion
Copy link

I'm on version 5.7.1 and import 'react-pdf/dist/Page/AnnotationLayer.css' doesn't work. I tried import 'react-pdf/dist/esm/Page/AnnotationLayer.css' but get this: image
Any other options for getting links to actually work in the rendered PDF?

This import got it working for me. import 'react-pdf/dist/esm/Page/AnnotationLayer.css';

Thanks, it perfectly work for me !

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

No branches or pull requests

5 participants