를 저장하는 파일을 처리하는 서비스 (다른 브라우저)의 소비자 싶습니다 : PDF 파일을 저장할 수있는 유일한 방법은 파일 이름이 필요합니다. 나는 다음 릴리스를 위해 이것을 바꿀 계획이 있다고 생각하지 않는다.
물리적 파일의 저장을 피하려면 작업 디렉토리가 필요합니다. pdf를 임시 파일에 저장하고 일단 보내면 삭제하십시오.
아주 기본적인 스크립트 내가 (임의의 파일 이름을 생성) 여기 가이 기능을 사용하고 JS Base64로 인코더있어
var page = require('webpage').create(),
system = require('system');
var fs = require('fs');
var Guid = function() {
function S4() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
// then to call it, plus stitch in '4' in the third group
return (S4() + S4() + "-" + S4() + "-4" + S4().substr(0, 3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();
}
var keyStr = "ABCDEFGHIJKLMNOP" +
"QRSTUVWXYZabcdef" +
"ghijklmnopqrstuv" +
"wxyz/" +
"=";
function encode64(input) {
input = escape(input);
var output = "";
var chr1, chr2, chr3 = "";
var enc1, enc2, enc3, enc4 = "";
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
keyStr.charAt(enc1) +
keyStr.charAt(enc2) +
keyStr.charAt(enc3) +
keyStr.charAt(enc4);
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < input.length);
return output;
}
if (system.args.length != 2) {
console.log('Usage: printer.js URL');
phantom.exit(1);
} else {
var address = system.args[1];
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
//create temporary file (current dir)
var tmpfileName = Guid() + '.pdf';
//render page
page.render(tmpfileName);
//read tmp file + convert to base64
var content = encode64(fs.read(tmpfileName));
//send (or log)
console.log(content);
//delete
fs.remove(tmpfileName);
phantom.exit();
}
});
}
을 수 있습니다.
감사합니다. 나는 그것이 사실이라고 생각했다. – TGH