Skip to content

Live preview of PDF #2475

Answered by CoskunCakir
nicholsss asked this question in Q&A
Jan 10, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

hey @nicholsss, I had to do something similar recently and ended up using react-pdf to preview the document so thought it might help

here how i have done;

import React, { useState, useEffect } from 'react';
import { Document, Page, pdfjs } from 'react-pdf';
import YourPDFDocument from './yourdocument';
import { usePDF } from '@react-pdf/renderer';

pdfjs.GlobalWorkerOptions.workerSrc = '/js/pdf.worker.min.js';

const Preview = () => {
  const [numPages, setNumPages] = useState(null);
  const [instance, updateInstance] = usePDF({ document: <YourPDFDocument /> });

  useEffect(() => {
    updateInstance();
  }, []);

  const onDocumentLoadSuccess = ({ numPages }) => {
    setNumPages(numPages)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nicholsss
Comment options

Answer selected by nicholsss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants