afpp 1.0.0 → 1.1.0
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/README.md +2 -0
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +4 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -19,6 +19,8 @@ But if you’ve encountered one or more of these issues:
|
|
|
19
19
|
- buggy as shit
|
|
20
20
|
- not working in esm/commonjs
|
|
21
21
|
- old pdfjs-dist as peer dependency
|
|
22
|
+
- no typescript support
|
|
23
|
+
- parsing of encrypted pdf files (password needed)
|
|
22
24
|
|
|
23
25
|
then you might find this package useful.
|
|
24
26
|
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pdf2string = void 0;
|
|
4
4
|
const promises_1 = require("node:fs/promises");
|
|
5
|
-
const parsePdfFileBuffer = async (
|
|
6
|
-
const fileBase64 = await (0, promises_1.readFile)(pathToFile, {});
|
|
5
|
+
const parsePdfFileBuffer = async (data, options) => {
|
|
7
6
|
return import("pdfjs-dist/legacy/build/pdf.mjs").then(async (pdfjsLib) => {
|
|
8
7
|
const loadingTask = pdfjsLib.getDocument({
|
|
9
|
-
data
|
|
8
|
+
data,
|
|
9
|
+
password: options?.password,
|
|
10
10
|
});
|
|
11
11
|
const pdfDocument = await loadingTask.promise;
|
|
12
12
|
const { numPages } = pdfDocument;
|
|
@@ -33,16 +33,19 @@ const parsePdfFileBuffer = async (pathToFile) => {
|
|
|
33
33
|
return pageContents;
|
|
34
34
|
});
|
|
35
35
|
};
|
|
36
|
-
|
|
37
|
-
const pdf2string = async (source) => {
|
|
36
|
+
const pdf2string = async (source, options) => {
|
|
38
37
|
if (typeof source === "string") {
|
|
39
|
-
|
|
38
|
+
const fileBase64 = await (0, promises_1.readFile)(source, {});
|
|
39
|
+
const data = new Uint8Array(fileBase64);
|
|
40
|
+
return parsePdfFileBuffer(data, options);
|
|
40
41
|
}
|
|
41
42
|
if (Buffer.isBuffer(source)) {
|
|
42
|
-
|
|
43
|
+
const fileBase64 = await (0, promises_1.readFile)(source, {});
|
|
44
|
+
const data = new Uint8Array(fileBase64);
|
|
45
|
+
return parsePdfFileBuffer(data, options);
|
|
43
46
|
}
|
|
44
47
|
if (source instanceof Uint8Array) {
|
|
45
|
-
return;
|
|
48
|
+
return parsePdfFileBuffer(source, options);
|
|
46
49
|
}
|
|
47
50
|
throw new Error(`Invalid source type: ${typeof source}`);
|
|
48
51
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAY5C,MAAM,kBAAkB,GAAG,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAY5C,MAAM,kBAAkB,GAAG,KAAK,EAAE,IAAgB,EAAE,OAAsB,EAAE,EAAE;IAC5E,OAAO,MAAM,CAAC,iCAAiC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;QACvE,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;YACvC,IAAI;YACJ,QAAQ,EAAE,OAAO,EAAE,QAAQ;SAC5B,CAAC,CAAC;QAEH,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC;QAE9C,MAAM,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC;QACjC,MAAM,YAAY,GAAa,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;QACnD,MAAM,YAAY,GAAmC,EAAE,CAAC;QAExD,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,QAAQ,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC;YACxD,YAAY,CAAC,IAAI,CACf,WAA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AAM,UAAU,GAAG,MAAM,IAAA,mBAAQ,EAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,MAAM,YAAY,UAAU,EAAE,CAAC;QACjC,OAAO,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,MAAM,EAAE,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEO,gCAAU"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
type ParseOptions = {
|
|
2
|
+
password?: string;
|
|
3
|
+
};
|
|
4
|
+
declare const pdf2string: (source: string | Buffer | Uint8Array, options?: ParseOptions) => Promise<string[]>;
|
|
2
5
|
export { pdf2string };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "afpp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "another f*cking pdf parser",
|
|
5
5
|
"types": "./dist/types/index.d.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"url": "https://github.com/l2ysho/afpp/issues"
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://github.com/l2ysho/afpp#readme",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"pdfjs-dist": "4.6.82"
|
|
38
|
+
},
|
|
36
39
|
"devDependencies": {
|
|
37
40
|
"@types/node": "22.5.5",
|
|
38
41
|
"semantic-release": "24.1.1",
|
|
39
42
|
"tsx": "4.19.1",
|
|
40
43
|
"typescript": "5.6.2"
|
|
41
|
-
},
|
|
42
|
-
"peerDependencies": {
|
|
43
|
-
"pdfjs-dist": "4.6.82"
|
|
44
44
|
}
|
|
45
45
|
}
|