Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render and show all pages #135

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function App() {
const { isWorkerInitialized, renderPage, loadDocument, currentPage } =
useMupdf();
const [pageImgUrl, setPageImgUrl] = useState<string | null>(null);

// ===> This is a demo effect which uses hooks <===
// ===> from useMupdf to load and display the first page <===
// ===> of the pdf as an image. <===
Expand All @@ -19,14 +19,14 @@ function App() {
const response = await fetch("/test.pdf");
const arrayBuffer = await response.arrayBuffer();
await loadDocument(arrayBuffer);
const pngData = await renderPage(currentPage);
const pngData = await renderPage(parseInt(location.pathname.slice(1)));
setPageImgUrl(
URL.createObjectURL(new Blob([pngData], { type: "image/png" }))
);
};

loadAndRender().catch(console.error);
}, [currentPage, isWorkerInitialized, loadDocument, renderPage]);
}, [currentPage, isWorkerInitialized, loadDocument, renderPage, location]);

return <>{pageImgUrl && <img src={pageImgUrl} />}</>;
}
Expand Down
3 changes: 2 additions & 1 deletion examples/react/src/hooks/useMupdf.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function useMupdf() {
}

setCurrentPage(pageIndex);

setIsWorkerInitialized(false);
return mupdfWorker.current!.renderPageAsImage(
pageIndex,
(window.devicePixelRatio * 96) / 72
Expand All @@ -56,5 +56,6 @@ export function useMupdf() {
loadDocument,
renderPage,
currentPage,
setCurrentPage
};
}
Loading