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
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)