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

228
Visualizações
How to store and retrieve the data from javascript function

I am new to javascript and I want to store the data from the function. This is the function I've written.

function OnlyReadOneText(txt){
    var file = event.target.files[0];
    var api = new FileReader();
    api.onload = function(){
            var typedarray = new Uint8Array(this.result)
            const task = pdfjsLib.getDocument(typedarray)
            task.promise.then((pdf) =>{
                console.log("This pdf has " + pdf.numPages + " pages")
                
                var countPromises = [];  
                for (var j = 1; j <= pdf.numPages; j++) {
                    var page = pdf.getPage(j);
                    var txt = "";

                    countPromises.push(page.then(function(page) { // add page promise
                    var textContent = page.getTextContent();
                    console.log(textContent );

                    return textContent.then(function(text){ // return content promise
                        return text.items.map(function (s) { 
                            return s.str; 
                        }).join(''); // value page text 
                    });
                    }));
                }
                    // Wait for all pages and join text
                    return Promise.all(countPromises).then(function (texts) {
                        txt = texts.join(''); //<---------------- I want this piece of info
                        return texts.join('');
                    });
            });
        }
        api.readAsArrayBuffer(file);  
   }

I do it in this way in javascript:

var ans = OnlyReadOneText();

It only return nothing no "ans". How to get texts.join and shown on ans?

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