将此 pdf 保存在 ionic 上的缓存/本地存储中
Save this pdf in the cache/local storage on ionic
Ho 给大家。我按照本教程创建了一个模态视图,其中包含使用 pdfmake 生成的 pdf。
http://gonehybrid.com/how-to-create-and-display-a-pdf-file-in-your-ionic-app/
我简单的问题是如何将本地存储中的pdf保存在缓存中?我需要它通过电子邮件发送pdf或使用openfile2打开它。我正在使用离子和科尔多瓦。
我不知道
你是如何编码的,但我知道你应该使用什么插件:
https://github.com/apache/cordova-plugin-file
git 包含插件的完整文档,因此您可能需要的一切都应该在那里。
使用Cordova文件和文件传输插件在设备中编写pdf文件的示例代码:
var fileTransfer = new FileTransfer();
if (sessionStorage.platform.toLowerCase() == "android") {
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, onFileSystemSuccess, onError);
} else {
// for iOS
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onError);
}
function onError(e) {
navigator.notification.alert("Error : Downloading Failed");
};
function onFileSystemSuccess(fileSystem) {
var entry = "";
if (sessionStorage.platform.toLowerCase() == "android") {
entry = fileSystem;
} else {
entry = fileSystem.root;
}
entry.getDirectory("Cordova", {
create: true,
exclusive: false
}, onGetDirectorySuccess, onGetDirectoryFail);
};
function onGetDirectorySuccess(dir) {
cdr = dir;
dir.getFile(filename, {
create: true,
exclusive: false
}, gotFileEntry, errorHandler);
};
function gotFileEntry(fileEntry) {
// URL in which the pdf is available
var documentUrl = "http://localhost:8080/testapp/test.pdf";
var uri = encodeURI(documentUrl);
fileTransfer.download(uri, cdr.nativeURL + "test.pdf",
function(entry) {
// Logic to open file using file opener plugin
},
function(error) {
navigator.notification.alert(ajaxErrorMsg);
},
false
);
};
相关文章:
- 将脚本缓存到本地存储的basket.js概念仍然是一个好主意吗
- “DOMException:找不到条目”时将大型响应放入缓存存储
- HTML5 本地存储作为缓存和单个资产请求
- 如何在浏览器中存储缓存
- 如何使用jquery将ajax响应存储在浏览器缓存中
- 将此 pdf 保存在 ionic 上的缓存/本地存储中
- AngularJS 工厂函数无法访问本地存储的缓存变量
- 如果我存储缓存并且已达到缓存限制会发生什么
- 如何验证“缓存控制”、“无缓存、无存储、必须重新验证”
- HTML5应用程序缓存文件存储在客户端的位置
- 缓存 Web 应用程序界面并使用 html5 本地存储恢复它
- Extjs 4 存储 - 查询整个存储,而不仅仅是缓存的记录
- 客户端存储/缓存大型HTML
- 将图像存储在浏览器缓存中-加载图像的最佳方式
- 显示缓存中存储的内容
- 如何在HTML5'中存储50MB视频;s应用程序缓存
- HTML5本地存储VS应用缓存离线网站浏览
- 如何在iOS中存储UIWebView缓存,使其在页面打开时不会闪烁
- 为什么这些记录不存储在缓存中
- 在HTML5本地存储中缓存整个jquery.min.js文件