@monolith-forensics/monolith-ui 1.2.112 → 1.2.113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPdfTextContent: (pdf: File) => Promise<string>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { pdfjs } from "react-pdf";
|
|
11
|
+
pdfjs.GlobalWorkerOptions.workerSrc = new URL("pdfjs-dist/legacy/build/pdf.worker.min.mjs", import.meta.url).toString();
|
|
12
|
+
export const getPdfTextContent = (pdf) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
const arrayBuffer = yield pdf.arrayBuffer();
|
|
14
|
+
const loadingTask = pdfjs.getDocument({ data: new Uint8Array(arrayBuffer) });
|
|
15
|
+
const pdfDoc = yield loadingTask.promise;
|
|
16
|
+
let fullText = "";
|
|
17
|
+
for (let pageNum = 1; pageNum <= pdfDoc.numPages; pageNum++) {
|
|
18
|
+
const page = yield pdfDoc.getPage(pageNum);
|
|
19
|
+
const content = yield page.getTextContent();
|
|
20
|
+
const pageText = content.items.map((item) => item.str).join(" ");
|
|
21
|
+
fullText += `\n\nPage ${pageNum}:\n${pageText}`;
|
|
22
|
+
}
|
|
23
|
+
return fullText;
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./getPdfTextContent";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./getPdfTextContent";
|