-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rules not working #141
Comments
Here's what I think you want to do: import { PdfReader, Rule } from "./index.js";
const processItem = Rule.makeItemProcessor([
// detect the first text entry that contain "hello"
Rule.on(/(hello.*)/i)
.extractRegexpValues()
.then((item) => {
console.log("found match:", item); // => found match: [ 'Hello "world"' ]
}),
// trigger the rule above, as soon as "hello" is found in a text entry
Rule.on(/hello/i).accumulateAfterHeading(),
]);
new PdfReader({}).parseFileItems("./test/sample.pdf", (err, item) => {
if (err) console.error("error:", err);
else if (!item) console.warn("end of file");
else processItem(item);
}); |
This is not working for me too. I did the following to import import { PdfReader, Rule } from 'pdfreader'; Importing Then running what was shown in the docs is not printing anything on the console const displayValue = (val: unknown) => {
console.log(val);
};
const displayTable = (val: unknown) => {
console.log(val);
};
const processItem = Rule.makeItemProcessor([
Rule.on(/^Hello "(.*)"$/)
.extractRegexpValues()
.then(displayValue),
Rule.on(/^Value:/)
.parseNextItemValue()
.then(displayValue),
Rule.on(/^c1$/).parseTable(3).then(displayTable),
Rule.on(/^Values:/)
.accumulateAfterHeading()
.then(displayValue)
]);
new PdfReader().parseFileItems(pdfpath, (err, item) => {
if (err) console.error(err);
else {
processItem(item);
}
}); What actually is the issue here? |
import { PdfReader } from 'pdfreader';
import { Rule } from 'pdfreader/Rule';
const processItem = Rule.makeItemProcessor([
Rule.on(/а/)
.extractRegexpValues()
.then((item) => console.log(item)),
]);
new PdfReader({}).parseFileItems('./pdf/1.pdf', (err, item) => {
if (err) console.error('error:', err);
else if (!item) console.warn('end of file');
else processItem(item);
});
What i need to paste in then() ?
The text was updated successfully, but these errors were encountered: