react-pdf-viewer
react-pdf-viewer copied to clipboard
Set the initial page does not work
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 There're 2 missing things:
- Import the styles
import "@react-pdf-viewer/core/lib/styles/index.css";
- Always put the
Viewerinside 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:
@phuoc-ng thanks for your help
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/