Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

92
Visualizações
Async Await returning undefined while using PDF parsing Library

I am building a project that parses PDFs.

I am having trouble with the order of returns of the functions below. Currently, the value I want is returned before the pdf buffer is completely parsed.

Order: Initialized variable is returned, and the rest of the code is run in the outer function, and then the page is fully parsed

Outer function

  // outer function iterates 
  const variable = await pdfPageParser(pdfBuffer, pageKey);

  // rest of the code 

Inner function

const pdfreader = require("pdfreader");

module.exports = async function pdfPageParser(
    pageBuffer, pageKey
) {
    let ENGR = false;
    let keyword = 'xyz';
 
     await new pdfreader.PdfReader().parseBuffer(pageBuffer,
        async function(err, item) {
            if (err) {
                console.log(err);
                return err
            } else if (!item) {
                console.log('Finish Parsing');
                return;
            } else if (item.text) {
                // check for keywords
                if (item.text.toLowerCase().includes(keyword)) {
                    ENGR = true;
                }
            };
        })

    return ENGR;
}

I would like the rest of the code to wait for the page to be completely parsed before continuing. How do I go about doing that?

I tried setting the return value of the await function but it returned undefined.

const ENGR = await new pdfreader.PdfReader().parseBuffer(pageBuffer,
        async function(err, item) {
            if (err) {
                console.log(err);
                return err
            } else if (!item) {
                console.log('Finish Parsing');
                return;
            } else if (item.text) {
                // check for keywords
                if (item.text.toLowerCase().includes(keyword)) 
                 return true
            };
        })
[...]
return ENGR

Thanks!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda