【问题标题】:Open or download pdf file for printing from Iphone using JS使用 JS 从 Iphone 打开或下载 pdf 文件以进行打印
【发布时间】:2017-12-01 19:55:29
【问题描述】:

如何使用 JS(Web 应用程序)在 Iphone 上打开或下载 PDF 文件。

我正在使用 window.open(src); 它可以在 android 和所有桌面操作系统上运行。但不是在 Iphone 上。

我从服务器生成 pdf 文件并想从手机打印该文件。这就是为什么我需要保存 pdf 文件或想直接从我的网络应用程序打印。

请帮忙。!! 提前感谢 :)

【问题讨论】:

  • “它不起作用”是什么意思,我的意思是它显示什么样的错误?
  • 没有任何错误,在mac上可以,但在iphone上不行。
  • 也可以试试 这也是但它会在 ios 上发出警告。

标签: javascript angularjs extjs sencha-touch


【解决方案1】:

只需创建一个如下所示的函数,然后传递 innerHTML。

openPrintWindow: 函数 (printHtmlStr) { var me = this;

var dt = new Date().getTime(); var html = '<!DOCTYPE HTML>' + '<html>' + '<head>' + '<meta http-equiv="x-ua-compatible" content="IE=Edge"/>' + '<link rel="stylesheet" type="text/css" href="appRes/css/print.css?_dc=' + dt + '" media="all" />' + '</head>' + '<body>' + '<div class="print">' + printHtmlStr + '</div>'; html += '</body>'; html += '</html>'; var iframe = this._printIframe; if (!this._printIframe) { iframe = this._printIframe = document.createElement('iframe'); document.body.appendChild(iframe); iframe.style.display = 'none'; iframe.onload = function () { setTimeout(function () { iframe.focus(); iframe.contentWindow.print(); }, 1); }; } iframe.src = "about:blank"; var doc = iframe.contentWindow.document; var windowUrl = window.location; // iframe.contentWindow.location; var uniqueName = new Date(); var windowName = 'Print' + uniqueName.getTime(); this.testwindow = doc.open(windowUrl, windowName); doc.write(html); doc.close(); }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-23
    • 2016-05-21
    • 2018-09-14
    • 2023-04-02
    • 1970-01-01
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多