压缩多个 PDF 并下载 zip 文件?
Zipping multiple PDFs and downloading the zip file?
正如描述所说:这是我的代码
var zip = new JSZip();
var urls = ["https://www.link.ca/documents/PDF/Quarters.pdf",
"https://www.link.ca/documents/PDF/Mills.pdf",
"https://www.link.ca/documents/PDF/Stop.pdf"
];
var count = 0;
var zipFilename = "Check_This_Out.zip";
urls.forEach(function (url) {
debugger;
var filename = "filename";
console.log(url);
JSZipUtils.getBinaryContent(url, function (err, data) {
if (err) {
throw err; // or handle the error
}
zip.file(url, data, {
binary: true
});
count++;
if (count == urls.length) {
zip.generateAsync({
type: "blob"
})
.then(function (blob) {
saveAs(blob, zipFilename);
});
}
});
});
我面临的问题是,当我解压缩它时,它会创建一个如下所示的文件夹结构:
C:\Users\samuser\Downloads\https_\www.link.ca\documents\PDF
我的 issue/question 是如何修复它以便当我打开 Zip 文件时,我应该看到我上传的三个文件。
如果有人遇到同样的问题,我就是这样解决的:
var filename = url.replace(/.*\//g, "");
zip.file(filename, data, { binary: true, createFolders: true });
正如描述所说:这是我的代码
var zip = new JSZip();
var urls = ["https://www.link.ca/documents/PDF/Quarters.pdf",
"https://www.link.ca/documents/PDF/Mills.pdf",
"https://www.link.ca/documents/PDF/Stop.pdf"
];
var count = 0;
var zipFilename = "Check_This_Out.zip";
urls.forEach(function (url) {
debugger;
var filename = "filename";
console.log(url);
JSZipUtils.getBinaryContent(url, function (err, data) {
if (err) {
throw err; // or handle the error
}
zip.file(url, data, {
binary: true
});
count++;
if (count == urls.length) {
zip.generateAsync({
type: "blob"
})
.then(function (blob) {
saveAs(blob, zipFilename);
});
}
});
});
我面临的问题是,当我解压缩它时,它会创建一个如下所示的文件夹结构:
C:\Users\samuser\Downloads\https_\www.link.ca\documents\PDF
我的 issue/question 是如何修复它以便当我打开 Zip 文件时,我应该看到我上传的三个文件。
如果有人遇到同样的问题,我就是这样解决的:
var filename = url.replace(/.*\//g, "");
zip.file(filename, data, { binary: true, createFolders: true });