0
我已经在手机中下载了一个PDF文件作为Base64字符串,如SO Thread中所述,但是我没有得到如何将其渲染为实际PDF,以便最终用户可以看到它?我写了下面的代码写在文件上:在Android/iOS应用程序中显示PDF
var tempResponse = null;
function downloadFileOK(response){
var invocationResult = response['invocationResult'];
tempResponse = invocationResult;
var size = parseInt(invocationResult["responseHeaders"]["Content-Length"]);
window.requestFileSystem(LocalFileSystem.PERSISTENT, size, onSuccessFileHandler, onErrorFileHandler);
}
//Success
function onSuccessFileHandler(fileSystem) {
alert("inside onSuccessFileHandler START");
fileSystem.root.getFile("test2.pdf", {create: true, exclusive: false}, fileWriter, fail);
alert("inside onSuccessHandler END");
}
// Failure
function onErrorFileHandler(error) {
alert("inside onErrorFileHandler");
}
function fileWriter(entry){
alert("inside fileWriter START");
entry.createWriter(function(writer){
writer.onwriteend = function(evt) {
console.log("done written pdf :: test1.pdf");
alert("Inside onwriteend : START");
};
var temp = atob(tempResponse["text"]);
alert(temp);
writer.write(temp);
},fail);
alert("inside fileWriter END");
}
function fail(error) {
alert("inside fail");
console.log(error.code);
}
我做错了吗?如何在iOS/Android操作系统中使用javascript/jquery/cordova从我的应用程序打开PDF?
@YoelNunez ...谢谢man..it没有很好地工作。我改变了一件事,而不是在window.open中传递'_blank',因为文件没有使用早期选项打开,所以我传递了'_system'。 –