我正在处理用jQuery编写的web scraper。我需要的是以Base64编码的字符串获取PDF文件。
我使用AJAX提交PDF:
$( '#myform' ).ajaxSubmit(function(data) {
alert.console(data);
});
控制台显示:
“%PDF-1.4% 30 obj<> / Subtype / Form / BBox [0 0 361 50] / Matrix [1 0 0 1 0 0] /长度3172 / FormType 1 / Filter / FlateDecode>>流 X \ M%)BJ + / lNIb#+ UO ?ׯ ?ׯ%GT;哦哦哦〜κ ՐW [→3< B%< LdKij / - 5 [Z&安培;߶7p“MF&安培; WQC f ǟI 9, JW p4 # + ZS pv 3I jHEL ˟Iz 꽰 Z 0 . (HWHz ^ -Ц ˟Ib
B
] LR BI T8 @ _n @ | $ ^ V}] [...]
确定。现在我需要Base64字符串。
我使用了FileReader,jQuery Base64 plugins,但编码后的字符串始终无效:
JVBERi0xLjQKJe + / VE + / VE + / VE + / vQozIDAgb2JqCjw8L1R5cGUvWE9iamVjdC9SZXNvdXJjZXM8PC9Qcm9jU2V0IFsvUERGIC9UZXh0IC9JbWFnZUIgL0ltYWdlQyAvSW1hZ2VJXT4 + L1N1YnR5cGUvRm9ybS9CQm94WzAgMCAzNjEgNTBdL01hdHJpeCBbMSAwIDAgMSAwIDBdL0xlbmd0aCAzMTcyL0Zvcm1UeXBlIDEvRmlsdGVyL0ZsYXRlRGVjb2RlPj5zdHJlYW0KeO + / VE + / vVxN77 + 9Je + / VE + / VE + / VE + / vSnvv70EQkrvv73vv73vv70VBu + / VE + / vSsvDO + / vQzvv70Y77 + 9B ++ / vWzvv73vv71O77 + 977 + 9GEnvv71i77 + 9Du + / VE + / vQvvv70jKwJVT ++ / vR0V77 + 977 + 9Xz / XR ++ / VE + / VE + / VE + / VE + / VT / XR ++ / VE + / VE + / vSXvv73vv70 + A ++ / VE + / VE + / vU8 / 77 + 977 + 9E3 / vv73vv71P77 + 977 + 9H2 / vv71 / 77 + 977 + 977 + 977 + 9H37vv73vv73vv73vv73vv71ff ++ / VE + / VE + / VE + / VE + / VE + / VE + / VC + W77 + 977 + 91ZDvv73vv70P77 + 9V ++ / VE + / VE + / VE + / vVvvv70 + 77 + 9Mzzvv73vv73vv73vv71 / 77 + 977 + 9H ++ / vUIlPO + / VE + / vUxk77 + 977 + 977 + + 9He / vUvvv73vv73vv70f77 + 977 + + 9aWrvv73vv73vv70v77 + 9Gu / vS3vv70177 + 9W1om77 + 977 + 977 + 977 + + 9HO / VD + [...]
如果我将文件保存到我的FS中,那么我可以执行:
$ base64 ~/tmp/myfile.pdf
我得到一个有效的Base64字符串:
JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlL1hPYmplY3QvUmVzb3VyY2VzPDwvUHJvY1Nl dCBbL1BERiAvVGV4dCAvSW1hZ2VCIC9JbWFnZUMgL0ltYWdlSV0 + Pi9TdWJ0eXBlL0Zvcm0vQkJv eFswIDAgMzYxIDUwXS9NYXRyaXggWzEgMCAwIDEgMCAwXS9MZW5ndGggMzE3Mi9Gb3JtVHlwZSAx L0ZpbHRlci9GbGF0ZURlY29kZT4 + c3RyZWFtCnicrVxBjiS3Ebz3K + YFRJGsYpFfMKCDTjoYvhm2 YXgFrC7 + vorMJDMq6YOBCexBwVTmRGCm2TmxsV0 / P8fXdXz9eP5zfP3nk0tc / 706 + Nfnt8 / VN / J1 六分之三十+ svT9O9PPL5 ++ fz1b8fX3z8 /新西兰/ fGv9 / hrXnqYac5X8oPsJxlBSfwvHCr + H + 549 / fq7QLvlC JVyXtAxkg6PFHfVL / ePz60vtahqaX6f / RX6HeMrsHe5TWgay0dHijhzyqt + 2Hw9q + g0cyEbr + 7tZ 1zf62 + TxCHeU4ZiCfj8Hslnp8WcSfw6T / gy1Kv + AQNib3JFEX0K5lf8OqSj / gEA4uvyZpOAOtaiC Gs75ExgQGEeXP5MUtHDo1Xtg0Ze1QGAcXf7MUZCOkPT + PbDqa1ugTUuXP5MUxHDqJUwpHFPBgMA4 [...]
这就是我的需要。任何人都可以帮助我吗?
提前致谢。