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

651
Visualizações
Is there a way to add pdfs to a jszip zip, using pdf-lib?

Good morning. As the title says i'm trying to add pdfs files to a zip. I'm using pdf-lib and jszip.

here's my switch case code where i'm implementing the logic:

case 'singolo':
        

        const zip = new JSZip();

        for(let i = 0; i < pages.length; i++){
            const pdf = await PDFDocument.create();
            const [copiedPages] = await pdf.copyPages(pdfFile, [i])
            pdf.addPage(copiedPages);
            const singlePdf = await pdf.save(); //format uint8array

            console.log('singlePdf', singlePdf)

            zip.file(`pagina ${i + 1}`, singlePdf)

        }

        zip.generateAsync({type: "blob"}) //ritorna una promise quindi posso usare il then
            .then(function(content) {
                saveAs(content, fileName ? fileName : `singoloPdf`); //metodo di fileSaver per poter scaricare lo zip
        });
        break;
    }

when i download the zip file, it contains not formatted files for being opened with adobe reader, but i've to specify with which program open them.

Anyone can point me the way?

Thanks in advance

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

i've resolved the issue by adding the file extension when adding the files.

So the previous line of code:

zip.file(`pagina ${i + 1}`, singlePdf)

Became:

zip.file(`pagina ${i + 1}.pdf`, singlePdf)
about 4 years ago · Juan Pablo Isaza Relatório
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