If you goal is just to view the pdf in your application, the easiest way is using the object tag in HTML. You don't need to import any libraries and works most of the browsers. But this is lack of customization and styles.
<object data="http://africau.edu/images/default/sample.pdf" type="application/pdf" width="100%" height="100%">
<p>Alternative text - include a link <a href="http://africau.edu/images/default/sample.pdf">to the PDF!</a></p>
</object>
Answer from Dhanuka Perera on Stack Overflow
» npm install react-pdf
Videos
» npm install pdf-viewer-reactjs
If you goal is just to view the pdf in your application, the easiest way is using the object tag in HTML. You don't need to import any libraries and works most of the browsers. But this is lack of customization and styles.
<object data="http://africau.edu/images/default/sample.pdf" type="application/pdf" width="100%" height="100%">
<p>Alternative text - include a link <a href="http://africau.edu/images/default/sample.pdf">to the PDF!</a></p>
</object>
it looks like you're passing the PDF data directly to the <ReactPDF> component as the value of the file prop. But according to the docs you need to use an object containing a data property:
<ReactPDF
file={{
data: renderPdf
}}
/>
it seems you can also set file to an object containing a url property, to let ReactPDF fetch the pdf from your backend by itself, if that's easier:
<ReactPDF
file={{
url: 'http://www.example.com/sample.pdf'
}}
/>
» npm install @pdf-viewer/react
I think this might be more of what your after. I wrapped it in a component for you already but this is a document viewer which can view PDF documents with out much work.
import React,{ Component } from 'react';
import ReactDOM from 'react-dom';
class DocView extends React.Component{
constructor(props){
super(props);
}
render(){
var url = "https://docs.google.com/viewerng/viewer?url="+this.props.src+"&embedded=true";
return(
<iframe style={this.props.style} src={url}></iframe>
);
}
}
export default DocView;
CloudPDF offers a React PDF viewer. It is basically pdf.js but then pre-rendered on the server. This gives the possibility for lazy loading of large pdf files and still keeping performance. And by default has a nice layout for the viewer.
import CloudPdfViewer from '@openbook/cloudpdf-viewer';
export default function () {
return (
<CloudPdfViewer documentId="346467a6-fa61-43ad-b45a-d1fdc3da0007" width="100%" height="500px" />
);
};
Disclamer: I am working for CloudPDF and it is still a beta version.
Hey, I wanted to find out a library in react which can display a pdf from a url. So far I have tried react-pdf from wojtekmaj, it works just fine but I wanted a free library which can provide toolbars also. Let me know if you know any library or a way to build it.
Thanks
Hey everyone,
I hope you're all doing well! 🖐️
I'm currently working on a React.js project that involves rendering PDFs on the client side, and I stumbled upon Mozilla's PDF.js library. While it seems promising, I'm facing some challenges when it comes to integrating it into my project and adding some basic tools like annotations and highlighting.However, I've been struggling to find comprehensive documentation on how to integrate PDF.js with React.js effectively.
Has anyone here successfully used PDF.js with React.js before? I'd really appreciate some guidance on the best practices for integration and any tips or resources to add basic tools for annotations and highlighting.
Feel free to share your experiences, code snippets, or any helpful tutorials that you've come across. Your insights will be of great help to a fellow developer.
Thank you all in advance! 😊🙏