4

I'm working on a website which serves PDF files (generated on the fly) for viewing and downloading by the user. The user needs to save these, sign them (using any 3rd party PDF app), then upload them. For this particular question we are focused on the handing off of the PDF from Chrome on iOS to a 3rd party PDF application.

On an unsecured, public website viewing a PDF from a public link such as this IRS form works fine. You can view it, then press "Open in..." in the bottom right and choose another application. The other application will receive the URL of the PDF and open it fine.

However, on a secured website, the hand-off does not happen correctly. After pressing "Open in..." in the bottom right on the PDF and choosing the 3rd party PDF app, the other app will receive the URL but not the cookies required to maintain session state. Therefore when it downloads the PDF it gets the login page of the website. Different applications handle this different but for instance, Google Drive will save the login page as a corrupt PDF file. Note that this works fine in Safari, the issue is with iOS Chrome.

What I've tried to do instead is to have the Chrome browser on iOS load the PDF as a blob, then create a data url and display the PDF using that:

<a id="myLink">Click here to test PDF data url</a>
<script>
    $('#myLink').click(function() {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', '/f1099msc.pdf');
        xhr.responseType = 'arraybuffer';
        xhr.onload = function(e) {
            if (this.status == 200) {
                var blob = new Blob([this.response], { type: 'application/pdf' });
                var reader = new FileReader();
                reader.onloadend = function() {
                    window.open(reader.result);
                };
                reader.readAsDataURL(blob);
            }
        };
        xhr.send();
        return false;
    });
</script>

This approach works fine and displays the PDF successfully. However, pressing "Open in..." in the bottom right to hand-off the PDF to another app does not work. Pressing it is unresponsive. I assume this is because of the large size of the data url, and that not being supported for hand-off to another app.

Any thoughts? How can I use iOS Chrome's "Open in" feature on iOS with PDF behind secured website or with a large data URL?

Here is an example page that will load a PDF as a data url. It works to display a PDF on Chrome iOS only. Other browsers aren't a fan of this method.

4

2 回答 2

4

问题的根源似乎是 Chrome for iOS 中实现的行为。在https://bugs.chromium.org/p/chromium/issues/detail?id=831678提出了一个问题,解决了缺少的 cookie。

作为一种替代方法,可以生成一个临时 URL,其中包含所有必要的身份验证详细信息,并且不依赖于与请求一起发送的 cookie。

使用这些临时 URL 在 Chrome 中打开 PDF。按“打开方式...”按钮将该临时 URL 传递给第三方应用程序。出于安全原因,您应该根据时间或调用次数停用临时 URL。还可以实施临时 URL 仅对该确切 IP 地址有效的限制。

于 2018-06-04T15:06:11.237 回答
0

我们需要有人对此进行调查,因为它仍然没有修复。但是我可能找到了一种解决方法,但它不适用于所有文件类型。对于 PDF,可以通过执行以下操作使用 iOS Chrome 修复错误“此时无法下载文件”:

  1. 在 iOS Chrome 中,输入地址:chrome://flags/
  2. 找到“在 Files.app 中打开下载”的标志并启用它
  3. 从现在开始,当您在安全站点中点击文档进行交互(在...中打开)时,将弹出共享表,其中包含下载 PDF 文件的选项,而不是之前的 HTML 文件。仍然困扰我的是这不适用于 .xls 或 .doc 文件或其他文档文件(因为它们不显示“在...中打开”对话框?)。我的问题是如何解决这个问题,因为我一直在寻找!
于 2020-09-30T16:16:31.507 回答