0

Hi, I'd like to display multiple pages of my PDF. I've followed the code sample on react-pdf. However, when I run the site on localhost, the PDF is installed rather than opened.

Please help

1. Error: enter image description here

2. Folder structure:

enter image description here

3. What I've tried:

  • Include the media queries
  • Try all suggested file path (public, import, relative)

4. Here's my code:

import React from "react";
import { Page } from "react-pdf";
import { pdfjs } from "react-pdf";
import { Document } from "react-pdf/dist/esm/entry.webpack";

import Lesson_1 from "./Lesson 1.pdf";
// import {} from '../../../public/docs/pdf/Lesson 1.pdf'

// pdfjs.GlobalWorkerOptions.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;

const options = {
  cMapUrl: "cmaps/",
  cMapPacked: true,
};

function Lesson(props) {
  const [numPages, setNumPages] = React.useState(null);
  const [pageNumber, setPageNumber] = React.useState(1);

  function onDocumentLoadSuccess({ numPages }) {
    setNumPages(numPages);
  }

  return (
    <div>
      <Document
        file="Lesson 1.pdf"
        options={options}
        onLoadSuccess={onDocumentLoadSuccess}
      >
        <Page pageNumber={pageNumber} />
      </Document>
      <p>
        Page {pageNumber} of {numPages}
      </p>
    </div>
  );
}


export default Lesson;

Ken Pham
  • 285
  • 6
  • 17
  • it looks more like a client issue, i.e. the way your browser handle a pdf that is opened. – Pac0 May 03 '21 at 02:40
  • Thanks for the comment @Pac0 . Would you mind helping me find out what is the issue in detail? I've tried to test the pdf on this browser with the library author's test suite and it works find – Ken Pham May 03 '21 at 03:14

0 Answers0