import React, { useState } from "react"; import { Document, Page, pdfjs } from "react-pdf"; pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js`; export default function PDFViewer(props) { const [numPages, setNumPages] = useState(null); const [pageNumber, setPageNumber] = useState(1); //default fisrt page function onDocumentLoadSuccess({ numPages }) { setNumPages(numPages); setPageNumber(1); } function changePage(offset) { setPageNumber(prevPageNumber => prevPageNumber + offset); } function previousPage() { changePage(-1); } function nextPage() { changePage(1); } const { pdf } = props; return ( <>

ページ {pageNumber || (numPages ? 1 : "--")} of {numPages || "--"}

); }