javascript - 如何抑制 `This document is trying to print. Do you want to allow this?`

标签 javascript pdf adobe foxit

我从 php 脚本创建一个 pdf,并希望该 pdf 在用户打开后立即打印出来。没有更多的互动。为此,我发现我可以添加一个 JavaScript,它可以使打印自动进行,理论上甚至不需要任何弹出窗口或警报。

我尝试了所有可以在所有论坛上找到的嵌入 JavaScript 组合,即:

  1. 将交互级别设置为静音或自动。

    $script = "var pp = getPrintParams(); pp.interactive = pp.constants.interactionLevel.silent; this.print(pp);"

  2. 旧样式:

$script = 'this.print({bUI: false, bSilent: true});

  • 设置要特权的函数:
  • $script = "sPrint = app.trustedFunction( function(){ app.beginPriv(); this.print({bUI:false, bSilent:true}); app.endPriv(); }); sPrint();"

    我什至尝试添加注册字段

    Acrobat Reader/DC/AVAlert/cCheckbox/cAcrobat/iWarnScriptPrintAll=1 Acrobat Reader/DC/EWH/bExecutePrint=1

    但是当我打开pdf时我仍然无法摆脱弹出的警报窗口。我尝试在 Adob​​e Reader DC 和 Foxit 中打开它。我收到同样的警告:

    This document is trying to print. Do you want to allow this?

    有谁知道如何抑制这个弹出窗口吗?谢谢。

    最佳答案

    未经用户同意或选择加入,您不能这样做。您可以在以下条件之一下使脚本以静默方式打印,但在每种情况下,用户都需要通过执行以下操作之一来选择加入。

    1. 允许您调用可信函数进行静默打印的脚本需要安装在用户计算机上的特权文件夹中。
    2. 文档可以保存到特权文件夹中。
    3. 您可以要求用户将您的域添加到特权域列表中。
    4. 签署文档并要求用户信任您的证书。

    请参阅 Acrobat JavaScript 文档的特权上下文部分 http://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/Acro12_MasterBook/JS_API_AcroJSPreface/Privileged_context.htm

    关于javascript - 如何抑制 `This document is trying to print. Do you want to allow this?`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42028987/

    相关文章:

    javascript - 如何使用 React 和 Office Fabric 在详细信息列表中聚焦按钮

    javascript - Angular Material 日期选择器尺寸错误

    java - 如何解析 "...is not available in this font' s编码”?

    pdf - GhostScript 错误

    jasper-reports - iText、JasperReports 和 Adob​​e LC 之间有什么区别?

    javascript - 是否可以从 array.filter 方法返回每个值而不是数组?

    javascript - 如何使用javascript存储Excel文件

    javascript - Momentis (PLM) 的 Photoshop 脚本

    html - 我们可以在 Dreamweaver 中使用 Cufon 吗?

    javascript - 即时添加 Javascript