在hyperref中使用表格中的TextField作为href(或PushButton)的URL。

问题描述 投票:0回答:1

所以我就是想不通这个问题。 在Latex的 "Form "环境中,想象一下有一个像下面这样的文本字段。

\TextField[default=URL_Here,bordercolor=,name=link1,width=8cm,charsize=10pt]{}

现在,如果你想在同一个表格块中的其他地方访问它,你可以这样做,但是,你如何将它转换为其他地方的超链接?

this.getField("link1").value

但是,你如何将其转换为其他地方的超链接? 最终的目标是,当在一个文本字段中输入一个URL时,一个可点击的链接会出现在相邻的字段中。 到目前为止,以下方法都失败了。

\href{this.getField("link1").value}{Link}

\PushButton[
    onclick={
        this.submitForm(this.getField("link1").value);
    },
    name=hlink1,
    readonly=false, bordercolor=, width=2cm, charsize=10pt
]{Link}

第一种方法只是在pdflatex编译时崩溃,而后一种方法成功了(只有在url中指定了https:/的情况下),但在试图访问某个任意url时失败了(为了匿名,将我的用户名改为USERNAME,复制如下)。

file:///C:/Users/USERNAME/AppData/Local/Temp/acrord32_sbx/A9Rcopupe_dxvlog_9x4.htm

上述提交按钮(失败)的最小测试案例如下。

\documentclass{article}

\usepackage{hyperref}

\begin{document}

\begin{Form}
\begin{tabular}{c | c }
\TextField[default=https://www.google.com,bordercolor=,name=link1,width=8cm,charsize=10pt]{} & 
\PushButton[
        onclick={
            this.submitForm(this.getField("link1").value);
        },
        name=hlink1,
        readonly=false, bordercolor=, width=2cm, charsize=10pt
    ]{Link}
\end{tabular}
\end{Form}

\end{document}
javascript latex hyperref
1个回答
0
投票

使用 app.launchURL() 在您的 MWE 中(而不是 submitForm())

\begin{Form}
\begin{tabular}{c | c }
\TextField[default=https://www.google.com,bordercolor=,name=link1,width=8cm,charsize=10pt]{} & 
\PushButton[
        onclick={
            app.launchURL(this.getField("link1").value);
        },
        name=hlink1,
        readonly=false, bordercolor=, width=2cm, charsize=10pt
    ]{Link}
\end{tabular}
\end{Form}

submitForm() 具有不同的功能。

submitForm

将表单提交到指定的URL。要调用此方法,您必须在Web浏览器内运行或安装了Acrobat Web Capture插件。如果URL使用 "mailto "方案,只要存在SendMail插件,即使不在Web浏览器内运行,也会被接受)。从Adobe Reader 6.0开始,你不需要在Web浏览器中调用这个方法。

-- 第345页

© www.soinside.com 2019 - 2024. All rights reserved.