Lyx 使用 JavaScript 生成的 PDF 遇到 NotAllowedError

Lyx 使用 JavaScript 生成的 PDF 遇到 NotAllowedError

我正在尝试生成一个 pdf 文件,并使用此代码打开另一个 pdf 文件

\usepackage[pdftex]{insdljs}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Main Script
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{insDLJS}{dljs}{Document Javascript}

doesitopen = app.trustedFunction (function() {
    var reffile1,openf;
    try {
        app.alert("trying c:/temp/existing.pdf",3);
        console.println('here');
        app.beginPriv();
            app.openDoc("/c/temp/existing.pdf");
        app.endPriv();
        openf = 1;
    }
    finally {
        e = null;
    }
    app.alert("diditopen",3);

});

doesitopen();
\end{insDLJS}

这是我的 Lyx 文件 - 它非常普通 -

#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass scrartcl
\begin_preamble
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document product, type, number and title
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Conditional text
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DO NOT ALTER AFTER THIS POINT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[pdftex]{hyperref}
\usepackage[pdftex]{eforms}
\input{jsfunctions_bare.tex}
\end_preamble
\use_default_options false
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman times
\font_sans helvet
\font_typewriter courier
\font_default_family sfdefault
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 83
\font_tt_scale 100

\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry true
\use_amsmath 1
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\use_refstyle 0
\index Index
\shortcut idx
\color #008000
\end_index
\leftmargin 1in
\topmargin 0.75in
\rightmargin 1in
\bottommargin 1.25in
\headheight 0in
\headsep 0.5in
\secnumdepth 3
\tocdepth 3
\paragraph_separation skip
\defskip medskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle fancy
\bullet 0 2 14 -1
\bullet 1 2 5 -1
\bullet 2 2 9 -1
\bullet 3 2 21 -1
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
\noindent
\align block

\series bold
Click below to test app.openDoc
\end_layout

\begin_layout Standard
\noindent
\align block
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
raisebox{-1.3pt}{
\backslash
pushButton[
\backslash
CA{Export}
\backslash
A{
\backslash
JS{doesitopen();}}]{export14}{12mm}{11pt}}
\end_layout

\end_inset


\end_layout

\end_body
\end_document

我的问题是 Adob​​e 拒绝执行我的代码,尽管已经使用并app.trustedFunction标记了我的代码app.beginPriv()app.endPriv()

当我运行 Adob​​e Reader XI 时,JavaScript 控制台中出现此错误:

Acrobat EScript 内置函数版本 11.0 Acrobat SOAP 11.0

NotAllowedError:安全设置阻止访问此属性或方法。App.trustedFunction:3:Document-Level:01 文档 Javascript

NotAllowedError:安全设置阻止访问此属性或方法。App.trustedFunction:1:Document-Level:01 文档 Javascript

NotAllowedError:安全设置阻止访问此属性或方法。App.trustedFunction:1:Document-Level:01 文档 Javascript

答案1

根据Acrobat 的 JavaScript API 参考,该方法app.trustedFunction受到安全限制,仅允许在批处理、控制台和应用程序初始化事件中使用,即不能在文档级 JavaScript 中使用。

另一方面,app.openDoc()不需要在受信任的环境中被调用。

所以,

\begin{insDLJS}{dljs}{Document Javascript}
  app.openDoc('c:/temp/existing.pdf');
\end{insDLJS}

应该已经可以工作了。

相关内容