현재로서는 불가능한 것 같습니다. 누구든지 해냈습니까? 방금 우편 번호 폴더에 추가하려는 몇 가지 PDF 파일이 있습니다!JSZip으로 서버에있는 PDF 압축
답변
죄송합니다.이 게시물의 링크가 부족하여 죄송합니다. stackoverflow에 대한 내 첫 번째 게시물이며 "2 개 이상의 링크를 게시하려면 10 개 이상의 평판이 필요합니다."라는 오류 메시지가 표시됩니다. (자세한 그 아래에,이 IE 6-9에서 작동하지 않습니다 경고)
는 PDF (또는 이진 파일), 당신은 원시의 콘텐츠를 얻을 수
xhr.responseType = "arraybuffer"
을 사용할 수를 다운로드합니다. jQuery를 사용하여이를 수행 할 수는 없지만 (github.com/jquery/jquery/pull/1525 참조) 원시 xhr 쿼리 또는 바이너리 데이터를 처리하는 모든 ajax 라이브러리가 작동합니다. 예를 들어 jszip-utils (github.com/Stuk/jszip-utils) (면책 조항 : 저는이 라이브러리의 제공자입니다).
JSZip 설명서에서 최근에 (github.com/Stuk/jszip/pull/114) 작업을 수행했으며 현재 수행하려는 작업의 예를 추가했습니다. 끌어 오기 요청이 아직 보류 중이므로 여기에 임시 URL이 있습니다. http://dduponchel.github.io/temp-jszip-documentation/documentation/examples/downloader.html
병합 후 http://stuk.github.io/jszip/documentation/examples/downloader.html이어야합니다.
이 기능은 JSZipUtils
를 사용하고 작동 것이다 ArrayBuffer 또는 Uint8Array를 반환 할 수있는 jQuery.Deferred
있지만 라이브러리에 결과를 포장 : 여기
var $form = $("#download_form").on("submit", function() {
var zip = new JSZip();
var deferreds = [];
// find every checked item
$(this).find(":checked").each(function() {
var url = $(this).data("url");
var filename = url.replace(/.*\//g, "");
deferreds.push(deferredAddZip(url, filename, zip));
});
// when everything has been downloaded, we can trigger the dl
$.when.apply($, deferreds).done(function() {
var blob = zip.generate({type:"blob"});
// see FileSaver.js
saveAs(blob, "example.zip");
}).fail(function (err) {
// handle the error here
});
return false;
});
주 :
/**
* Fetch the content, add it to the JSZip object
* and use a jQuery deferred to hold the result.
* @param {String} url the url of the content to fetch.
* @param {String} filename the filename to use in the JSZip object.
* @param {JSZip} zip the JSZip instance.
* @return {jQuery.Deferred} the deferred containing the data.
*/
function deferredAddZip(url, filename, zip) {
var deferred = $.Deferred();
JSZipUtils.getBinaryContent(url, function (err, data) {
if(err) {
deferred.reject(err);
} else {
zip.file(filename, data, {binary:true});
deferred.resolve(data);
}
});
return deferred;
}
이, 그것은 saveAs
위한 polyfill로 FileSaver.js 메인 함수 이용한다 jszip 및 jszip 유틸-IE를 지원하지만없이 6-9 ArrayBuffer/Uint8Array, 성능이 떨어집니다.
편집 : 링크 JSZip의 Utils GitHub의 : https://github.com/Stuk/jszip-utils
감사합니다. 내 친구, 설명대로 작동합니다. 도움을 다시 한번 감사드립니다! –
글쎄, 그것은 당신의 브라우저가 인터넷에 연결 임의의 시스템의 디스크에서 파일을 훔칠 수 없다는 분명하다. 하지만 아마도 URL을로드 할 수 있습니다. 너의 문제는 정확히 뭐야? –
동일한 출처 정책에 관해 읽으십시오. J는 임의의 위치에서 임의의 파일을 가져올 수 없습니다. – Nit
PDF 파일은 내 도메인에 있습니다. 기본적으로 내가 원하는 것은 현재 찾고있는 것보다 더 복잡하지만 현재 사용자가 내 서버에있는 몇 개의 PDF가 포함 된 zip 파일을 다운로드하기 위해 클릭하는 버튼이 필요합니다. –