简体   繁体   English

检查是否在PDF中打开了JavaScript对话框

[英]Check if JavaScript dialog box is open in a PDF

I'm trying to make a pair of dialog boxes that show upon opening a PDF; 我正在尝试创建一个在打开PDF时显示的对话框。 one dialog will show if the PDF is opened in a reader that supports Adobe Reader's level of JavaScript functionality, and the other will show if the previous dialog is not shown (ie, if the PDF is opened in a reader with little JavaScript support, which means the first dialog cannot be shown). 一个对话框将显示是否在支持Adobe Reader的JavaScript功能级别的阅读器中打开PDF,另一个对话框将显示是否未显示上一个对话框(即,如果在不支持JavaScript的阅读器中打开PDF,表示无法显示第一个对话框)。

The problem I'm running into right now is trying to get the second dialog to show. 我现在遇到的问题是试图显示第二个对话框。 I tried using a try-catch, but I'm assuming it didn't work because the first dialog box didn't actually fail to show... or something. 我尝试使用try-catch,但是我假设它没有用,因为第一个对话框实际上并没有显示...。

So how would I go about showing the second dialog if the first is not shown due to a lack of support? 那么如果由于缺乏支持而没有显示第一个对话框,我该如何显示第二个对话框?

Here's my current code (which is written as a "page open" action in the page properties): 这是我当前的代码(在页面属性中写为“打开页面”操作):

try {
     var d = dialog();

     d.execDialog();
} catch (e) {
     app.alert("ERROR: Incompatible reader; please install Adobe Reader to open this file.");
}

function dialog()
{
     var dialogDescriptor =
    {
        // Dialog description goes here
    };

     var dialogObject =
    {
        execDialog: function() { return app.execDialog(dialogDescriptor); },
    };

 return dialogObject;

}

The reason I'm using app.execDialog is because there will be hyperlinks in the first dialog box. 我使用app.execDialog的原因是因为第一个对话框中将有超链接。

Also, I'm completely new to using JavaScript and working with PDFs, so I apologize if this is a dumb question. 另外,我对使用JavaScript和处理PDF完全陌生,因此,如果这是一个愚蠢的问题,我深表歉意。

You can check to see if the PDF viewer supports the Dialog object by testing if app.execDialog is a function. 您可以通过测试app.execDialog是否为函数来检查PDF查看器是否支持Dialog对象。 Something like this... 像这样

if (typeof app.execDialog === "function") {
    // Can show Acrobat dialogs    
}
else {
    // Can't show Acrobat Dialogs
}  

That kind of code works for any function or object method. 这种代码适用于任何函数或对象方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM