Print Page | Close Window

Add a working hyperlink to RTF-enabled text box?

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
URL: http://forums.planetpdf.com/forum_posts.asp?TID=4011
Printed Date: 16 Jul 2019 at 6:10am
Software Version: Web Wiz Forums 11.10 - http://www.webwizforums.com


Topic: Add a working hyperlink to RTF-enabled text box?
Posted By: mmitchell_houston
Subject: Add a working hyperlink to RTF-enabled text box?
Date 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 - https://www.w3schools.com" );
getField("txtbox2").value = result;

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

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





Replies:
Posted By: mmitchell_houston
Date 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.


Posted By: gkaiseril
Date Posted: 03 Sep 2018 at 12:38am
Have you looked at the https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2FJavaScript_API.htm - Acrobat JavaScript API Reference Manual?

You might try using the https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2Fapp_methods.htm%23TOC_launchURLbc-19&rhtocid=_6_1_8_6_1_18 - 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.


Posted By: mmitchell_houston
Date Posted: 04 Sep 2018 at 5:39pm
Originally posted by gkaiseril gkaiseril wrote:

Have you looked at the https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2FJavaScript_API.htm - 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?




Posted By: BAlheit
Date Posted: 05 Sep 2018 at 10:00am
spans doesn't have a hyperlink property.


Posted By: mmitchell_houston
Date 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.


Posted By: BAlheit
Date Posted: 06 Sep 2018 at 9:53am
Not all features are available in JavaScript.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 - http://www.webwizforums.com
Copyright ©2001-2017 Web Wiz Ltd. - https://www.webwiz.net