Skip to content

armgit / ui

Public Imported from GitHub
0
TypeScript

Serve PDF viewer sample locally

Andrew Luoc3d8471285c0
diff --git a/apps/v4/components/pdf-viewer-docs.tsx b/apps/v4/components/pdf-viewer-docs.tsx
index b263a94..00c74d0 100644
--- a/apps/v4/components/pdf-viewer-docs.tsx
+++ b/apps/v4/components/pdf-viewer-docs.tsx
@@ -212,6 +212,7 @@ pdfjs.GlobalWorkerOptions.workerSrc =
"/legacy/build/pdf.worker.min.mjs";
const ZOOM_OPTIONS = [0.5, 0.75, 1, 1.25, 1.5, 2];
+const DEFAULT_PDF_URL = "/path/to/document.pdf";
const PAGE_RENDER_BUFFER = 2;
const PAGE_BASE_WIDTH = 612;
const PAGE_BASE_HEIGHT = 792;
@@ -538,7 +539,7 @@ const PdfPages = memo(function PdfPages({
);
});
-function Component({ url }: { url: string }) {
+function Component({ url = DEFAULT_PDF_URL }: { url?: string }) {
const [numPages, setNumPages] = useState<number | null>(null);
const [currentPage, setCurrentPage] = useState(1);
const [zoom, setZoom] = useState(0.5);
diff --git a/apps/v4/components/pdf-viewer-preview-client.tsx b/apps/v4/components/pdf-viewer-preview-client.tsx
index bb51dce..e21eb52 100644
--- a/apps/v4/components/pdf-viewer-preview-client.tsx
+++ b/apps/v4/components/pdf-viewer-preview-client.tsx
@@ -38,7 +38,7 @@ import {
pdfjs.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${pdfjs.version}/legacy/build/pdf.worker.min.mjs`
const ZOOM_OPTIONS = [0.5, 0.75, 1, 1.25, 1.5, 2]
-const SAMPLE_PDF_URL = "https://arxiv.org/pdf/1706.03762"
+const SAMPLE_PDF_URL = "/samples/attention.pdf"
const PAGE_RENDER_BUFFER = 2
const PAGE_BASE_WIDTH = 612
const PAGE_BASE_HEIGHT = 792
diff --git a/apps/v4/public/samples/attention.pdf b/apps/v4/public/samples/attention.pdf
new file mode 100644
index 0000000..97d7c51
Binary files /dev/null and b/apps/v4/public/samples/attention.pdf differ