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.

Links not clickable in the rendered pdf.

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, 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';

1reaction
tjsudarsancommented, 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';

Read more comments on GitHub >

github_iconTop Results From Across the Web

PDF Links Not Working? Here's How To Fix It - TechNewsToday
How to Fix PDF Links Not Working? · Insert the Correct URL · Enable the Anchor Links · Set Default PDF Viewer ·...
Read more >
How to render pdf with clickable links? - android
I use PdfRenderer class to render pdf. However, the problem is that in this approach I can't make the hyperlinks in the document...
Read more >
Clickable links in PDF rendering - Google Groups
Hello everybody,. I generated a PDF rendering of a Webpage. Text is selectable (only on Linux – for a weird reason on OSX...
Read more >
Links not clickable in iMessage app | Apple Developer Forums
Sometimes, URL links in received messages are not clickable. ... then apple pay takes over and the subsequent links are rendered as unclickable...
Read more >
Are links inside pdf clickable when viewing the pd...
Not if you use the PDF macro. However, if you use the new PDF previewing functionality the links do work. To use that...
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