【问题标题】:priniting a pdf genrated from php from a iframe using js使用js从iframe打印从php生成的pdf
【发布时间】:2015-06-26 06:34:25
【问题描述】:

我有这个代码

<!DOCTYPE HTML>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="lolkittens" />

    <title>Untitled 2</title>
</head>

<body>

<p>Don't forget to print your document!</p>
<iframe src="genpdf.php" id="pdfDocument"></iframe>

<script>


function printPage() { print(); }

function printIframe(id)
{
    var iframe = document.frames ? document.frames[id] : document.getElementById(id);
    var ifWin = iframe.contentWindow || iframe;
    iframe.focus();
    ifWin.printPage();
    return false;
}

printIframe('pdfDocument');
</script>

</body>
</html>

礼貌Open Printer Dialog for PDF file Automatically

但是我一直收到这个错误...

TypeError: ifWin.printPage 不是函数

不太确定我做错了什么以及如何解决(FF 和 chrome 中的问题)..

提前致谢。

【问题讨论】:

  • 它说“function printPage() { print(); }”应该进入 iframe ......我厌倦了在实际的 php 文件中添加一个不起作用的脚本标签...... . 如何将脚本添加到 iframe ?????
  • 贴出iframe的代码
  • @Ankit iframe 页面是一个纯php页面,生成一个pdf ....
  • 然后直接调用iFrame的打印方法,我在下面的答案中说

标签: javascript php pdf iframe


【解决方案1】:

是的,你需要将 printPage 函数放在 iframe 中,但是还有另一种方法你可以直接调用 iframe 的窗口对象的 print 方法,而无需 printPage() 之类的

ifWin.print();

而不是

ifWin.printPage();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-26
    • 1970-01-01
    • 2013-09-22
    • 2023-03-10
    • 2012-11-19
    • 2023-03-06
    相关资源
    最近更新 更多