Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

645
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda