【发布时间】:2022-01-07 09:04:21
【问题描述】:
早上好。正如标题所说,我正在尝试将 pdfs 文件添加到 zip 中。我正在使用 pdf-lib 和 jszip。
这是我实现逻辑的开关案例代码:
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;
}
当我下载 zip 文件时,它包含未格式化的文件,无法使用 adobe reader 打开,但我必须指定使用哪个程序打开它们。
谁能给我指路?
提前致谢
【问题讨论】:
标签: javascript reactjs zip jszip