自从iOS7存在以来,我在jsPDF上遇到了很大的麻烦。我们开发了一个网络应用程序,并使用jsPDF动态创建PDF。我们在一个新的Safari窗口中打开PDF,这样用户就可以访问Adobe Reader,通过邮件发送PDF或执行其他操作。在iOS6中这是没有问题的,但是在iOS7中你不能在新窗口中打开data:application/pdf;base64链接!注意:只有当您将Web应用程序添加到您的主屏幕时,才会发生这种情况。
如果有人有解决方案、变通方法或其他有用的信息,我会很高兴听到。
发布于 2014-02-07 21:50:30
找到解决方案了!!创建html文件(例如pdf.html)并添加
<!DOCTYPE html><html>
<head>
<title></title>
</head>
<body>
<script>
document.location.href = document.location.hash.substr(1);
</script>
</body>
</html>创建链接
<a class="btn btn-default" id="pdfData" ng-show="isMobile && pdfReady" ref="app/views/pdf.html" target="xxx">
Download PDF
</a>在你“渲染”你的pdf之后,获取datauristring并把它作为散列添加到你的链接中。
var pdfData = doc.output('datauristring');
var element = document.getElementById('pdfData');
element.href = "app/views/pdf.html#" + pdfData;
element.target = "xxx";
$scope.pdfReady = true; // show download link现在,如果用户单击下载链接,将在safari中打开一个新窗口,并显示pdf。
发布于 2014-02-04 22:19:38
你试过使用doc.output('dataurlnewwindow')吗?
如果这不起作用,您可以创建一个新的路由,如/pdf/download?data=base64data...,并根据给定的参数数据用Content-Type: application/pdf响应那里的pdf。一定要避免可能的安全问题,这样其他人就不能向pdfs提供您的url。
https://stackoverflow.com/questions/20978473
复制相似问题