Open sajanpknair opened 2 years ago
I am also having the exact same issue. Did you find a solution for it?
Unfortunately I could not find a way around this other than forcing it with a "any" cast.
Since the TextItem and TextMarkedContent classes are not exported by pdfjs-dist, there's no way to use instanceof
to test against.
Trying with hasOwnProperty
also does not suppress the error either.
You should guard against TextMarkedContent by checking if 'str' is undefined
or falsey.
Ditto here. pdfjs
is remarkable. Improved type accuracy and availability around TextItem | TextMarkedContent
would be a delight. :)
Changing s.str to s['str'] fixed the issue for me. Thanks for the help.
// item: TextItem | TextMarkedContent
if ("src" in item) {
// access to item
}
// item: TextItem | TextMarkedContent if ("src" in item) { // access to item }
wow thank my case i did this
for (const textItem of textItems.items) {
if ("str" in textItem) {
text += textItem?.str;
}
}
setExtractedText(text);
// console.log(extr actedText)
} catch (error) {
console.error('Error extracting text:', error);
// Handle the error, e.g., display an error message to the user
}
Dear Team: I have been trying to extract text from pdf and I am following this tutorial : https://onthecode.co.uk/parse-pdf-documents-in-angular-with-pdfjs/ .
'countPromises.push(textContent.items.map((s) => s.str).join(''));' is throwing error. It says "Property 'str' does not exist on type 'TextItem | TextMarkedContent'. ", in s.str. Any help would be appreciated.
Angular CLI: 13.2.3 Node: 14.15.5 Package Manager: npm 6.14.11 OS: darwin x64
Angular: 13.2.2 ... animations, common, compiler, compiler-cli, core, forms ... platform-browser, platform-browser-dynamic, router
Package Version
@angular-devkit/architect 0.1302.3 @angular-devkit/build-angular 13.2.3 @angular-devkit/core 13.2.3 @angular-devkit/schematics 13.2.3 @angular/cli 13.2.3 @schematics/angular 13.2.3 rxjs 7.5.4 typescript 4.5.5