Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS 7 (and newer) can't open PDF in new browser window #165

Closed
atroy opened this issue Jan 8, 2014 · 14 comments
Closed

iOS 7 (and newer) can't open PDF in new browser window #165

atroy opened this issue Jan 8, 2014 · 14 comments

Comments

@atroy
Copy link

atroy commented Jan 8, 2014

I know it is not really a jsPDF related issue, but I think many jsPDF users facing the same problem and if someone has a solution for that it would be nice to post it here.

http://stackoverflow.com/questions/20978473/ios-7-and-newer-cant-open-pdf-in-new-browser-window

@diegocr
Copy link
Collaborator

diegocr commented Feb 6, 2014

Does iOS7 accepts blob:xxx URls? If it does, you can get a blob and use createObjectURL & revokeObjectURL to open such a blob uri instead of the data: one.

@MrRio
Copy link
Member

MrRio commented Feb 6, 2014

If that doesn't work for whatever reason, you could use a:

var newWin = window.open();
newWin.document.write('insert jsPDF script tag and jsPDF calls here');

Then your new window just generates the PDF.

@atroy
Copy link
Author

atroy commented Feb 7, 2014

@MrRio Thanks for your response, but window.open() does not work in "home screen" web apps since iOS7. I will try @diegocr s solution and write if it works.

@MrRio
Copy link
Member

MrRio commented Feb 7, 2014

I found this on Stack Overflow:

"Having an anchor tag with target _blankwill work in iOS 7.0.3"

http://stackoverflow.com/questions/18879631/how-to-open-safari-from-a-webapp-in-ios-7

So perhaps you use JS to add an Download to the page.

On Fri, Feb 7, 2014 at 10:12 AM, Alexander Troy notifications@github.comwrote:

@MrRio https://github.com/MrRio Thanks for your response, but
window.open() does not work in "home screen" web apps since iOS7. I will
try @diegocr https://github.com/diegocr s solution and write if it
works.


Reply to this email directly or view it on GitHubhttps://github.com//issues/165#issuecomment-34423520
.

James Hall
Director

Parallax

+44 113 322 6477
http://parall.ax/

Registered office: The Old Brewery, High Court, Leeds, LS2 7ES
Registered in England no. 07430032
VAT No. 101 3405 84

@atroy
Copy link
Author

atroy commented Feb 7, 2014

Does also not work in Web App only in Safari... the only thing that works is target="xxx" not blank than you can open http websites but not "data:application/pdf..." hrefs.

@MrRio
Copy link
Member

MrRio commented Feb 7, 2014

Good to know, must be some weird bug in Mobile Safari.

@atroy
Copy link
Author

atroy commented Feb 7, 2014

@diegocr can you reopen it, still an issue. I submittend also a Bugreport to Apple, but as long as it not works we should leave it open, that others see that it needs to be fixed / or have another solution.

@MrRio MrRio reopened this Feb 7, 2014
@MrRio
Copy link
Member

MrRio commented Feb 7, 2014

I wonder if we could engineer a workaround that inserts an invisible one of those into the DOM then does a click event on it?

Is there any way to detect that we're in a "Home screen" app?

@atroy
Copy link
Author

atroy commented Feb 7, 2014

Yes, window.navigator.standalone returns true if it is "web-app-capable" and pinned to home screen.

What do you like to insert? I also tried to insert a link and trigger a click event with the same result - only works in safari not in home screen.

@atroy
Copy link
Author

atroy commented Feb 7, 2014

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" href="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

@atroy atroy closed this as completed Feb 7, 2014
@diegocr
Copy link
Collaborator

diegocr commented Feb 7, 2014

Neat solution, thanks for sharing it! and sorry for my late reply, i was away.

@BenRoe
Copy link

BenRoe commented Jun 17, 2014

@atroy thanks for the working solution.
There is a small typing error »ref="app/views/pdf.html"« -> »href="app/views/pdf.html"«

@atroy
Copy link
Author

atroy commented Jun 17, 2014

@BenRoe you're welcome and thanks edited!

@jakobklein
Copy link

Great workaround! In addition to the IOs-problem, the accepted solution solved two more issues in my case:

IE9: You can now download pdf-results in IE9 without using downloadify
Safari 5.1: Download was not possible if I embedded the result of html2canvas in a pdf using jspdf

@atroy : Thanks alot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants