0

So I just can't seem to figure this out. In a Latex "Form" environment, imagine having a textfield like the following:

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

Now, if you want to access this elsewhere in the same Form block, you can do so with:

this.getField("link1").value

But, how can you then convert that to a hyperlink elsewhere? The end goal is to have it so that when a URL is input in one textfield, a clickable link appears in an adjacent field. So far, the following methods all fail:

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

and

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

The first approach simply crashes on pdflatex compilation, and the latter succeeds (only if https:// is specified in the url), but fails as it tries to access some arbitrary url (copied below with my username changed to USERNAME for anonymity):

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

A minimal test case of the above submit button (that fails) is as follows:

\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}
hherbol
  • 91
  • 12
  • I don't think you can do this with LaTeX, since LaTeX sets a document in PDF that is fixed. You'll have to use dynamic components of the PDF language (perhaps Javascript) to obtain this effect. – Werner Jan 25 '19 at 04:50
  • @Werner - I understand that part, but I can't seem to figure out exactly how to approach this. I know there's a "calculate" field in TextField that allows for javascript injection (which I have used successfully in another use case); however, I can't seem to get it to work for setting up a hyperlink. That's why in the above example I try using javascript in the onclick field of thhe PushButton, but it's not exactly going as planned. – hherbol Jan 25 '19 at 21:46

1 Answers1

0

Use app.launchURL() in your MWE (instead of 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() has a different function:

submitForm

Submits the form to a specified URL. To call this method, you must be running inside a web browser or have the Acrobat Web Capture plug-in installed. (If the URL uses the “mailto” scheme, it will be honored even if not running inside a web browser, as long as the SendMail plug-in is present.) Beginning with Adobe Reader 6.0, you need not be inside a web browser to call this method.

-- Page 345

escalator
  • 888
  • 9
  • 14