paper-manager 0.2.4 → 0.2.5
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.
package/dist/pdf/extractor.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Document } from "@langchain/core/documents";
|
|
2
2
|
export declare function extractPdfContent(pdfPath: string): Promise<Document[]>;
|
package/dist/pdf/extractor.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { Document } from "@langchain/core/documents";
|
|
3
|
+
import { PDFParse } from "pdf-parse";
|
|
2
4
|
export async function extractPdfContent(pdfPath) {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
+
const data = await readFile(pdfPath);
|
|
6
|
+
const parser = new PDFParse({ data });
|
|
7
|
+
const result = await parser.getText();
|
|
8
|
+
await parser.destroy();
|
|
9
|
+
return result.pages.map((page) => new Document({
|
|
10
|
+
pageContent: page.text,
|
|
11
|
+
metadata: {
|
|
12
|
+
source: pdfPath,
|
|
13
|
+
pdf: { totalPages: result.total },
|
|
14
|
+
loc: { pageNumber: page.num },
|
|
15
|
+
},
|
|
16
|
+
}));
|
|
5
17
|
}
|
|
6
18
|
//# sourceMappingURL=extractor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../src/pdf/extractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../src/pdf/extractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAAe;IACrD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IACtC,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IAEvB,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CACrB,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,QAAQ,CAAC;QACX,WAAW,EAAE,IAAI,CAAC,IAAI;QACtB,QAAQ,EAAE;YACR,MAAM,EAAE,OAAO;YACf,GAAG,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE;YACjC,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;SAC9B;KACF,CAAC,CACL,CAAC;AACJ,CAAC"}
|