modesty / modesty/pdf2json

Unexpected error "stream must have data"

Open
#106 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
2.2k
Forks
394
Avg merge
3d 5h
Merged PRs (30d)
7

Description

From time to time I got this error message An error occurred while parsing the PDF: stream must have data. Some time I pass all pdfs without error and some time with error.
I have 2000 pdfs stored on disk, with loop fetch one by one and I want extract text.

async function parsePdf(file: any): Promise<any> {
  return new Promise((resolve, reject) => {
    const pdfParser = new PDFParser(this, 1);
    pdfParser.loadPDF(file.path);

    pdfParser.on("pdfParser_dataError", errData => {
      console.error(errData);
      reject(errData.parserError)
    });
    pdfParser.on("pdfParser_dataReady", pdfData => resolve(pdfParser.getRawTextContent()));
  });
}

Is someone can help me with this issue. Where I'm wrong. Thank you.

EDIT:
If I use call directly with buffer, everything work as expected.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the parsePdf entry point and the PDFParser.loadPDF(file.path) call, then compare that path-based flow with the buffer-based flow mentioned in the edit. Reproduce the intermittent error across the stored PDFs and identify what must change so all files are processed without the “stream must have data” error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.