Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
Async Espera regresar indefinido al usar la biblioteca de análisis de PDF

Estoy construyendo un proyecto que analiza archivos PDF.

Tengo problemas con el orden de retorno de las siguientes funciones. Actualmente, el valor que quiero se devuelve antes de que el búfer pdf se analice por completo.

Orden: se devuelve la variable inicializada, y el resto del código se ejecuta en la función externa, y luego la página se analiza por completo

función exterior

 // outer function iterates const variable = await pdfPageParser(pdfBuffer, pageKey); // rest of the code

función interna

 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; }

Me gustaría que el resto del código esperara a que la página se analizara por completo antes de continuar. ¿Cómo hago para hacer eso?

Intenté establecer el valor de retorno de la función de espera pero volvió indefinido.

 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

¡Gracias!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!