本文介绍了iOS 7(及更新版本)无法在新的浏览器窗口中打开PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于iOS7存在,我遇到了jsPDF的大麻烦。我们开发了一个Web应用程序,并使用jsPDF即时创建PDF。我们在新的Safari窗口中打开PDF,以便用户可以访问Adobe Reader以通过Mail发送PDF或执行其他操作。在iOS6中这没有问题,但在iOS7中你无法在新窗口中打开数据:application / pdf; base64 链接!请注意,只有在将Web应用程序添加到主屏幕时才会发生这种情况。

I have big trouble with jsPDF since iOS7 exists. We developed a Web App and used jsPDF to create PDFs on-the-fly. We open the PDF in a new Safari window so that the user gets access to Adobe Reader to send the PDF via Mail or do other things. In iOS6 this was no problem, but in iOS7 you can't open data:application/pdf;base64 links in a new window! Note this only happens if you add the Web App to your homescreen.

如果有人有解决方案,解决方法或其他有用的信息,我将很高兴听到。

If someone has a solution, a workaround or other helpful informations I would be glad to hear.

推荐答案

有一个解决方案!
创建一个html文件(例如pdf.html)并添加

Got a solution!!Create a html file (eg pdf.html) and add

<!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 并将其作为哈希添加到您的链接。

After you "rendered" your pdf get the datauristring and add it to your link as hash.

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

And now if the user clicks the download link a new window is opened in safari and the pdf get shown

这篇关于iOS 7(及更新版本)无法在新的浏览器窗口中打开PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 13:32
查看更多