This commit is contained in:
20
scripts/read-pdf.mjs
Normal file
20
scripts/read-pdf.mjs
Normal file
@@ -0,0 +1,20 @@
|
||||
import fs from 'node:fs';
|
||||
import { PDFParse } from 'pdf-parse';
|
||||
|
||||
const path = process.argv[2];
|
||||
if (!path) {
|
||||
console.error('Usage: node read-pdf.mjs <pdf-path>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const buf = fs.readFileSync(path);
|
||||
const parser = new PDFParse({ data: buf });
|
||||
await parser.load();
|
||||
const info = await parser.getInfo();
|
||||
const text = await parser.getText();
|
||||
console.log('Pages:', info.numPages);
|
||||
console.log('Title:', info.info?.Title || 'none');
|
||||
console.log('Author:', info.info?.Author || 'none');
|
||||
console.log('---CONTENT---');
|
||||
console.log(text.text);
|
||||
await parser.destroy();
|
||||
Reference in New Issue
Block a user