Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
834 views
in Technique[技术] by (71.8m points)

web applications - iOS 7 (and newer) can't open PDF in new browser window

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

Create a link

<a class="btn btn-default" id="pdfData" ng-show="isMobile && pdfReady" ref="app/views/pdf.html" target="xxx">
Download PDF
</a>

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...