Links not clickable in the rendered pdf.
See original GitHub issueI 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!
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:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This import got it working for me.
import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
@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';