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

111
Visualizações
Problem with read file pdf from URL nodeJS

I'm using pdf.js-extract to read data pdf file from URL. This is my code and it runs well:

const fs = require('fs');
const PDFExtract = require('pdf.js-extract').PDFExtract;
const pdfExtract = new PDFExtract();
const https = require('https');

const url = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf'

const readData = async (url) => {
    https.get(url, async function (response) {
        const file = fs.createWriteStream('./dummy.pdf');
        response.pipe(file);
        file.on("finish", () => {
            pdfExtract.extract('./dummy.pdf', {})
            .then(async function(data) {
                console.log(data)
            });
            file.close();
            fs.unlinkSync('./dummy.pdf')
        });
    });
}

readData(url)

But I have 2 problem about this code.

  1. The first is that how can I deal with if the url changes from https to http, I try node-fetch but it's seem not work as I expected.
  2. The second one is that the code take too long to handle if the pdf file is large, about 5 seconds for 2 Mbs. I wonder if there is a faster way like reading the file from the buffer or something like that without having to save it as a temporary file

Thanks for your attention

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