使用 jszip 将 pdf 的 zip 保存在文件夹中
Save zip of pdf in folder with jszip
我不知道如何正确使用 jsZip..
我正在尝试从本地主机的文件夹中获取文件,然后将其压缩,最后将压缩文件保存在同一文件夹中...
但我真的不太了解如何使用它
这是我所做的:
JSZipUtils.getBinaryContent("http://localhost:8100/pdf/test.pdf", function (err, data) {
if(err) {
alert('err');
throw err;
}
else{
zip.file("test.pdf",data,{binary:true})
.then(function (blob) {
saveAs(blob, "pdf.zip");
});
}
});
有人可以帮助我吗?
下面的代码对我有用。
注意,这是针对 jszip utils 版本 3 的。它需要 filesaver.js 才能使 saveAs 调用正常工作 (https://github.com/eligrey/FileSaver.js)。
这是我的代码:
function create_zip(){
// get checked file urls
var urls = Array();
$("input:checked").each(function () {
urls.push($(this).siblings('a').attr('href'));
})
console.log(urls);
var zip = new JSZip();
var count = 0;
var zipFilename = "archive.zip";
urls.forEach(function(url){
var filename = url.substr(url.lastIndexOf("/")+1);
console.log(filename);
// loading a file and add it in a zip file
JSZipUtils.getBinaryContent(url, function (err, data) {
if(err) {
throw err; // or handle the error
}
zip.file(filename, data, {binary:true});
count++;
if (count == urls.length) {
zip.generateAsync({type:'blob'}).then(function(content) {
saveAs(content, zipFilename);
});
}
});
});
};
改编自此处的信息:https://gist.github.com/noelvo/4502eea719f83270c8e9
希望对您有所帮助!
var zip = new JSZip();
JSZipUtils.getBinaryContent(url, function (err, data) {
if(err) {
alert('err');
throw err;
}
else{
zip.file("test.csv",data,{binary:true});
zip.generateAsync({ type: "Blob" }).then(function (content) {
fsaver.saveAs(content, "example.zip");
});
}
});
为 angular 试试这个。这是一个 csv 文件。将 url 作为 csv 文件的路径。
我不知道如何正确使用 jsZip.. 我正在尝试从本地主机的文件夹中获取文件,然后将其压缩,最后将压缩文件保存在同一文件夹中...
但我真的不太了解如何使用它
这是我所做的:
JSZipUtils.getBinaryContent("http://localhost:8100/pdf/test.pdf", function (err, data) {
if(err) {
alert('err');
throw err;
}
else{
zip.file("test.pdf",data,{binary:true})
.then(function (blob) {
saveAs(blob, "pdf.zip");
});
}
});
有人可以帮助我吗?
下面的代码对我有用。
注意,这是针对 jszip utils 版本 3 的。它需要 filesaver.js 才能使 saveAs 调用正常工作 (https://github.com/eligrey/FileSaver.js)。
这是我的代码:
function create_zip(){
// get checked file urls
var urls = Array();
$("input:checked").each(function () {
urls.push($(this).siblings('a').attr('href'));
})
console.log(urls);
var zip = new JSZip();
var count = 0;
var zipFilename = "archive.zip";
urls.forEach(function(url){
var filename = url.substr(url.lastIndexOf("/")+1);
console.log(filename);
// loading a file and add it in a zip file
JSZipUtils.getBinaryContent(url, function (err, data) {
if(err) {
throw err; // or handle the error
}
zip.file(filename, data, {binary:true});
count++;
if (count == urls.length) {
zip.generateAsync({type:'blob'}).then(function(content) {
saveAs(content, zipFilename);
});
}
});
});
};
改编自此处的信息:https://gist.github.com/noelvo/4502eea719f83270c8e9
希望对您有所帮助!
var zip = new JSZip();
JSZipUtils.getBinaryContent(url, function (err, data) {
if(err) {
alert('err');
throw err;
}
else{
zip.file("test.csv",data,{binary:true});
zip.generateAsync({ type: "Blob" }).then(function (content) {
fsaver.saveAs(content, "example.zip");
});
}
});
为 angular 试试这个。这是一个 csv 文件。将 url 作为 csv 文件的路径。