PDF Viewer Using Web Viewer

|
| By Navneet Kaur

Pdf viewer is used for viewing pdf using javascript. We can Add a PDF.js viewer to any application with out-of-the-box annotations, PDF form filling, and signing. A free in-browser PDF viewer is PDF.js Express Viewer. It contains capabilities like text search, text selection, and high-fidelity zooming, as well as a lovely, resizable user interface.

Full Documentation:
https://pdfjs.express/

Code: Preview pdf with Web viewer in react js
import WebViewer, { getInstance } from '@pdftron/pdfjs-express-viewer';
function Preview(props) {
useEffect(() => {
const instance = getInstance();
if (instance) {
instance.UI.loadDocument(PDF_URL);
return;
}
WebViewer(
{
path: '/webviewer/lib',
licenseKey: LICENSE_KEY,
initialDoc: PDF_URL,
enableReadOnlyMode: true
},
viewer.current,
).then((instance) => {
const { documentViewer } = instance.Core;
documentViewer.addEventListener('documentLoaded', () => {
instance.setFitMode(instance.FitMode.FitWidth)
})
});
}

Leave a Reply

Your email address will not be published. Required fields are marked *