Skip to content
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

Failed assertion 'tream' == line when parsing this PDF #50

Closed
asedilloglatt opened this issue Jan 6, 2024 · 2 comments · Fixed by #51
Closed

Failed assertion 'tream' == line when parsing this PDF #50

asedilloglatt opened this issue Jan 6, 2024 · 2 comments · Fixed by #51

Comments

@asedilloglatt
Copy link

I am trying to search the text of this PDF I attached 3776_A_City_Council_24-01-09_Notice_and_Agenda.pdf

Here is the function I wrote to search:

static Future pdfContainsText(
String pdfUriString, String searchText) async {
if (pdfUriString.isEmpty || searchText.isEmpty) {
return true;
}

print(pdfUriString);
return await http
    .get(Uri.parse(pdfUriString))
    .then((response) {
      print(response.contentLength);
      return PDFParser(ByteStream(response.bodyBytes)).parse();
    })
    .then((doc) => doc.catalog)
    .then((catalog) => catalog.getPages())
    .then((pages) async {
      String allText = '';
      final firstPage = pages.getPageAtIndex(0);
      PDFPageNode? node = firstPage;
      while (node != null) {
        print(await node.resources);
        allText += (await node.resources).toString();
        node = node.parent;
      }
      return allText;
    })
    .then((pdfTextContent) => pdfTextContent.contains(searchText));

}

I am getting this error when i run my code.
Unhandled exception:
'package:dart_pdf_reader/src/parser/pdf_object_parser.dart': Failed assertion: line 259 pos 12: ''tream' == line': is not true.
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
errors_patch.dart:51
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
errors_patch.dart:40
#2 PDFObjectParser._parseStream (package:dart_pdf_reader/src/parser/pdf_object_parser.dart:259:12)
pdf_object_parser.dart:259

#3 PDFObjectParser.parse (package:dart_pdf_reader/src/parser/pdf_object_parser.dart:29:28)
pdf_object_parser.dart:29

#4 parseTrailer (package:dart_pdf_reader/src/parser/pdf_parser.dart:63:10)
pdf_parser.dart:63

@NicolaVerbeeck
Copy link
Owner

NicolaVerbeeck commented Jan 6, 2024 via email

@NicolaVerbeeck
Copy link
Owner

Release 0.5.1 will fix parsing the PDF. Though as I said, the text is not contained in the resources (which contains things like fonts and images)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants