react-pdf-viewer icon indicating copy to clipboard operation
react-pdf-viewer copied to clipboard

Set the initial page does not work

Open jjbier opened this issue 5 years ago • 3 comments

Hi I set the initial page manually. But the page always is not loads I am doing something wrong?

import { Worker, Viewer } from "@react-pdf-viewer/core";
import demoFile from "./demo.pdf";

export default function App() {
  return (
    <Worker workerUrl="https://unpkg.com/[email protected]/build/pdf.worker.min.js">
      <Viewer fileUrl={demoFile} initialPage={2} />
    </Worker>
  );
}

https://codesandbox.io/s/fast-fog-bdnf5?file=/src/App.js

jjbier avatar Apr 11 '21 10:04 jjbier

@jjbier There're 2 missing things:

  • Import the styles
import "@react-pdf-viewer/core/lib/styles/index.css";
  • Always put the Viewer inside a fixed container
<div style={{ height: "720px" }}>
  <Viewer fileUrl={demoFile} initialPage={2} />
</div>

Here is the update version https://codesandbox.io/s/pensive-leakey-sy01h?file=/src/App.js:

phuocng avatar Apr 11 '21 13:04 phuocng

@phuoc-ng thanks for your help

jjbier avatar Apr 12 '21 07:04 jjbier

I feel like the docs could make this a lot clearer, especially for the "Set the initial page" example https://react-pdf-viewer.dev/examples/set-the-initial-page/

Jbarget avatar Oct 19 '23 13:10 Jbarget