Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Add a working hyperlink to RTF-enabled text box?
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Add a working hyperlink to RTF-enabled text box?

 Post Reply Post Reply
Author
mmitchell_houston View Drop Down
New Member
New Member
Avatar

Joined: 29 Aug 2018
Location: Houston, TX
Points: 10
Post Options Post Options   Quote mmitchell_houston Quote  Post ReplyReply Direct Link To This Post Topic: Add a working hyperlink to RTF-enabled text box?
    Posted: 01 Sep 2018 at 11:46pm
Two Questions
  1. Is it  possible to programmatically create a working link inside an rtf-enabled text field?
  2. If not, is it possible to create a link in the clipboard memory and then paste it into the field (I know this sounds weird, but since I can copy a working link from MS Word and paste it into the form, I'm wondering if this desperate play might be possible)?


SCENARIO:
txtbox1 = standard text field (text only, no rtf)
txtbox2 = text box with rtf enabled (+ multiline, scrolling, etc.)
btnSubmit = standard button

  1. User will type url into txtbox1
  2. User will click btnSubmit
  3. Javascript will paste url into txtbox2 as a fully working URL that the user can click

IS THIS POSSIBLE?

I have experimented with two approaches, and neither works.

FIRST (RTF approach) I tried set it with something similar to this

var newURLrtf1 =  "{\colortbl ;\red0\green0\blue238;}{\field{\*\fldinst HYPERLINK" + getField("txtbox1").value + " }{\fldrslt{\ul\cf1Text to display}}}"
getField("txtbox2").value = newURLrtf1

(I know, that code won't work exactly as written -- I'm looking at the concept, not the syntax here)

SECOND (HTML approach) I tried to set it with something similar to this:
    var str = "The description goes here";
var result = str.link("https://www.w3schools.com");
getField("txtbox2").value = result;

I even tried this.
  getField(txtbox2").innerHTML = newURLrtf1;

------------------------------


Back to Top
Sponsored Links


Back to Top
mmitchell_houston View Drop Down
New Member
New Member
Avatar

Joined: 29 Aug 2018
Location: Houston, TX
Points: 10
Post Options Post Options   Quote mmitchell_houston Quote  Post ReplyReply Direct Link To This Post Posted: 01 Sep 2018 at 11:47pm
I am sorry, I should have mentioned that the approaches cited above both work about halfway: the text does move over to the second box, but all the code appears as visible text. It does not work to create a link.
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4099
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 03 Sep 2018 at 12:38am
Have you looked at the Acrobat JavaScript API Reference Manual?

You might try using the app.launchURL. Carefully read the description and the sections about privileged context. If this form will be distributed to others, then you or they will have to install a special script file in one of Acrobat's/Reader's JavaScript folders.
Back to Top
mmitchell_houston View Drop Down
New Member
New Member
Avatar

Joined: 29 Aug 2018
Location: Houston, TX
Points: 10
Post Options Post Options   Quote mmitchell_houston Quote  Post ReplyReply Direct Link To This Post Posted: 04 Sep 2018 at 5:39pm
Originally posted by gkaiseril gkaiseril wrote:

Have you looked at the Acrobat JavaScript API Reference Manual?
Thank you. That has lead me down some promising avenues. I've learned that I the richValue of a RTF field is an array, and it can be accessed and written to:

To get the text stored in richValue, use this:
     getField("txtboxName1").richValue.toSource();


I can populate the RTF field in this manner:

// Build up an array of Span objects
   var spans = new Array();
   spans[0] = new Object();
   spans[0].hyperlink = "http://www.bhp.com";
   spans[0].text = "My Text Here\r";
   spans[0].textColor = color.blue;
   spans[0].textSize = 10;

   spans[1] = new Object();
   spans[1].text = "Adobe Acrobat 6.0\r";
   spans[1].textColor = color.red;
   spans[1].textSize = 20;
   spans[1].alignment = "center";
   
   spans[2] = new Object();
   spans[2].text = "More text here";
   spans[2].textColor = color.blue;
   spans[2].fontStyle = "italic";
   spans[2].underline = true;
   spans[2].alignment = "right";
   

   // Now give the rich field a rich value
   getField("txtboxName1").richValue = spans;

The line of blue text above DOES NOT work.
Can someone suggest something that might let me create a clickable hyperlink?


Back to Top
BAlheit View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 1107
Post Options Post Options   Quote BAlheit Quote  Post ReplyReply Direct Link To This Post Posted: 05 Sep 2018 at 10:00am
spans doesn't have a hyperlink property.
Back to Top
mmitchell_houston View Drop Down
New Member
New Member
Avatar

Joined: 29 Aug 2018
Location: Houston, TX
Points: 10
Post Options Post Options   Quote mmitchell_houston Quote  Post ReplyReply Direct Link To This Post Posted: 05 Sep 2018 at 5:01pm
Originally posted by BAlheit BAlheit wrote:

spans doesn't have a hyperlink property.
Yup. I figured that out.

QUESTION: If the RTF field allows me to copy/paste a working URL into it (or I can use the Text Property Editor to add one), how does that work? Why does it allow me to paste it in if I cannot extract it later?

This just seems peculiar to me.
Back to Top
BAlheit View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 1107
Post Options Post Options   Quote BAlheit Quote  Post ReplyReply Direct Link To This Post Posted: 06 Sep 2018 at 9:53am
Not all features are available in JavaScript.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.016 seconds.