modesty / modesty/pdf2json

getRawTextContent() method not consistent in multiple sequential calls

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

This code parses two pdf files and converts to rawtext and removes the line starting with 'Generated' and then compares those two text files.This method is called more than once sequentially and for each call the arguments to the method changes, but the raw content is not getting replaced for the last call.

function compareGeneratedReportContent(samplePDFFile, sampleXLSXText) {
    const pdfParser = new PDFParser(this, true)
    const pdfParser2 = new PDFParser(this, true)
    const pdfExportPath = path.join(__dirname, '../../resources/report-test/PDFExportedFile.pdf')
    const xlsxExportPath = path.join(__dirname, '../../resources/report-test/XLSXExportedFile.xlsx')
    let content1 = ''
    let content2 = ''
    let result = false

    pdfParser2.on('pdfParser_dataError', errData => console.log(errData))
    pdfParser2.on('pdfParser_dataReady', () => {
        content2 = pdfParser2.getRawTextContent().replace(/^.*(Generated).+$/mg, '')
        // console.log('content2 ', content2)
        fs.writeFileSync(path.join(__dirname, '../../resources/report-test/sample.txt'), content2, 'utf-8')
    })
    pdfParser2.loadPDF(path.join(__dirname, `../../resources/report-test/${samplePDFFile}.pdf`))

    pdfParser.on('pdfParser_dataError', errData => console.log(errData))
    pdfParser.on('pdfParser_dataReady', () => {
        content1 = pdfParser.getRawTextContent().replace(/^.*(Generated).+$/mg, '')
        // console.log('content1 ', content1)
        fs.writeFileSync(path.join(__dirname, '../../resources/report-test/generated.txt'), content2, 'utf-8')
    })
    pdfParser.loadPDF(pdfExportPath)

    let readContent2 = fs.readFileSync(path.join(__dirname, '../../resources/report-test/sample.txt'), 'utf-8')
    let readContent1 = fs.readFileSync(path.join(__dirname, '../../resources/report-test/generated.txt'), 'utf-8')
    if (readContent2 === readContent1) {
        console.log('Report pdf file content matches')
        result = true
    } else {
        console.log('Error in matching contents of report pdf')
        result = false
    }
}

```Can anybody help?
Regards,
Fazi

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 at getRawTextContent() and the pdfParser_dataReady handlers in compareGeneratedReportContent, then reproduce the reported behavior with sequential calls using different PDF arguments. Verify that each call returns and writes the raw content for its own input rather than retaining content from an earlier call.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.