Skip to content

Commit 5b7cfbb

Browse files
feat: use react-pdf-viewer
use react pdf viewer and provide a toolbar that zooms in and out, changes page number and downloads file. Now viewer works on mobile chrome too
1 parent b5836ef commit 5b7cfbb

File tree

6 files changed

+245
-26
lines changed

6 files changed

+245
-26
lines changed

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public-hoist-pattern[]=pdfjs-dist

next.config.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ await import("./src/env.js");
66

77
/** @type {import("next").NextConfig} */
88
const config = {
9+
swcMinify: false,
10+
911
images: {
1012
domains: ["res.cloudinary.com"],
1113
},
12-
webpack: (
13-
config, options
14-
) => {
14+
webpack: (config, options) => {
15+
config.resolve.alias.canvas = false;
1516
config.module.rules.push({
1617
test: /\.node/,
17-
use: 'raw-loader',
18+
use: "raw-loader",
1819
});
1920
return config;
2021
},

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"react-dropzone": "^14.3.8",
5353
"react-hot-toast": "^2.5.2",
5454
"react-icons": "^5.5.0",
55+
"react-pdf": "^9.2.1",
5556
"tailwind-merge": "^2.6.0",
5657
"tailwindcss-animate": "^1.0.7",
5758
"zod": "^3.24.3"

pnpm-lock.yaml

+92-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/CatalogueContent.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ import {
2424
SheetTitle,
2525
SheetTrigger,
2626
} from "./ui/sheet";
27+
export async function downloadFile(url: string, filename: string) {
28+
try {
29+
const response = await axios.get(url, { responseType: "blob" });
30+
const blob = new Blob([response.data]);
31+
const link = document.createElement("a");
32+
link.href = window.URL.createObjectURL(blob);
33+
link.download = filename;
34+
link.click();
35+
window.URL.revokeObjectURL(link.href);
36+
} catch (error) { }
37+
}
2738

2839
const CatalogueContent = () => {
2940
const router = useRouter();
@@ -213,17 +224,6 @@ const CatalogueContent = () => {
213224
setSelectedPapers([]);
214225
}, []);
215226

216-
async function downloadFile(url: string, filename: string) {
217-
try {
218-
const response = await axios.get(url, { responseType: "blob" });
219-
const blob = new Blob([response.data]);
220-
const link = document.createElement("a");
221-
link.href = window.URL.createObjectURL(blob);
222-
link.download = filename;
223-
link.click();
224-
window.URL.revokeObjectURL(link.href);
225-
} catch (error) { }
226-
}
227227

228228
return (
229229
<div className="relative flex min-h-screen justify-center p-0 md:justify-normal">

0 commit comments

Comments
 (0)