UNPKG

@pdf-viewer/react

Version:

A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.

38 lines (37 loc) 1.13 kB
import { useState as S, useCallback as m, useEffect as d } from "react"; import { convertPDFDate as l } from "../convertPdfDate.js"; import { formatFileSize as w } from "../formatFileSize.js"; const D = (n, t, s) => { const [u, p] = S(), c = m(async () => { if (!t || !n) return; const r = await t.getMetadata().then(), P = t.numPages, e = r == null ? void 0 : r.info, a = await t.getDownloadInfo(); let f = 0; a && (f = a.length); try { const o = l(e.CreationDate), i = l(e.ModDate), g = { pageCount: P, filename: s || "", fileSize: w(f), title: e.Title, author: e.Author, subject: e.Subject, keywords: e.Keywords || "", creator: e.Creator, createdOn: (o == null ? void 0 : o.toISOString()) || "", modifiedOn: (i == null ? void 0 : i.toISOString()) || "", pdfProducer: e.Producer, pdfVersion: e.PDFFormatVersion }; p(g); } catch (o) { console.log("properties err", o); } }, [t, s, n]); return d(() => { c(); }, [c]), u; }; export { D as usePdfProperties };