modesty / modesty/pdf2json

Can't process multiple pdf files

Open
#98 1 comment 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

Is there an easy way to process multiple files? I have this:

 var PDFParser = require('pdf2json');
 var pdfParser = new PDFParser();
 var fs = require('fs');
 var fileNames = [];
 var fileCont = 0;

 fs.readdir(fileFolder, function(err, files){
      for (var i = files.length - 1; i >= 0; i--) {
      if (files[i].indexOf('.pdf') !== -1){
           fileNames.push(files[i]);
      }

      pdfParser.loadPDF(fileNames[fileCont]);
 });

 pdfParser.on('pdfParser_dataReady', function(data){
      //Do all my stuff and insert in db...

      fileCont++;

      If (fileCont === fileNames.lenght){
            for (var i = fileNames.length - 1; i >= 0; i--) {
                 fs.unlink(fileFolder + fileNames[i]);
            }
           return res.json({
                data: 'ok '
           });
      }

      pdfParser.loadPDF(fileFolder + fileNames[fileCont]);
 })

But is failing as the dataReady event if firing on the same pdf file always

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 with the usage shown in the issue, especially the pdfParser.loadPDF calls and the pdfParser_dataReady handler. Reproduce processing several files and trace which filename is passed to each load; done means each distinct PDF is processed once and the completion response is sent after all files finish.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.