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

后端 未结 2 6223
抹茶落季
抹茶落季 2020-12-20 00:29

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 get

相关标签:
2条回答
  • 2020-12-20 01:08

    Have you tried using doc.output('dataurlnewwindow')?

    If that doesn't work, you could make a new route like /pdf/download?data=base64data... and response the pdf there with Content-Type: application/pdf and based on the given parameter data. Be sure to avoid possible security issues, so that no other one can provide pdfs with your url.

    0 讨论(0)
  • 2020-12-20 01:14

    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

    0 讨论(0)
提交回复
热议问题