I want to be able to programatically select the TextBox tool and when clicked, a default text box appears on the PDF document with text already in it. This is not a PDF Tools item of something behind the scenes but interactive with the user. Use Case as follows:
1. User is looking at a document.
2. User clicks a custom menu button to add text.
3. System responds by adding a text box to the document with default text such as, "12/10/2009 /jstonis". The text is dynamic and set at the time of button click.
Can you send a code snippet of how to do this? Is it possible?
Thanks,
Jon
Programatically Set TextBox Text
Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
-
- Site Admin
- Posts: 2448
- Joined: Thu Jun 30, 2005 4:11 pm
Re: Programatically Set TextBox Text
Hi, Jon
HTH
What is "custom menu button"? We are currently do not support customization of our context menus (it will be available in the future).1. User is looking at a document.
2. User clicks a custom menu button to add text.
If you talking about your context menu item above then you may:3. System responds by adding a text box to the document with default text such as, "12/10/2009 /jstonis". The text is dynamic and set at the time of button click.
Code: Select all
OnClickOnYourContextMenuItem()
{
// Method A:
// place your dynamic text into the system clipboard and call:
AX.DoVerb("", "ExecuteCommand", "Paste", 0, 0);
// or Method B:
// obtain current page:
AX.GetProperty("Documents[0].Pages.Current", curPage, 0);
// and call:
AX.RunJavaScript("this.addAnnot({Page: <curPage>, type: "FreeText", contents: "12/10/2009 /jstonis", rect: [0, 0, 100, 100]})", NULL, <DocID>, 0);
};
PDF-XChange Co. LTD (Project Developer)
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
-
- User
- Posts: 12
- Joined: Thu Mar 26, 2009 1:01 pm
Re: Programatically Set TextBox Text
I got the Clipboard method to work but am struggling with the JavaScript. I am using c#. I converted your syntax to this:
private void btnTryThis_Click(object sender, EventArgs e)
{
object curPage;
pdfActiveX.GetProperty("Documents[0].Pages.Current", out curPage, 0);
// and call:
string sResult;
//axCoPDFXCview1.RunJavaScript(TBText.Text, out sResult, 0, 0);
pdfActiveX.RunJavaScript("this.addAnnot({Page: <curPage>, type: \"FreeText\", contents: \"12/10/2009 jstonis\", rect: [0, 0, 100, 100]})", out sResult, 0, 0);
}
But when run, I get a COM Exception. Any ideas?
Jon
private void btnTryThis_Click(object sender, EventArgs e)
{
object curPage;
pdfActiveX.GetProperty("Documents[0].Pages.Current", out curPage, 0);
// and call:
string sResult;
//axCoPDFXCview1.RunJavaScript(TBText.Text, out sResult, 0, 0);
pdfActiveX.RunJavaScript("this.addAnnot({Page: <curPage>, type: \"FreeText\", contents: \"12/10/2009 jstonis\", rect: [0, 0, 100, 100]})", out sResult, 0, 0);
}
But when run, I get a COM Exception. Any ideas?
Jon
-
- Site Admin
- Posts: 2448
- Joined: Thu Jun 30, 2005 4:11 pm
Re: Programatically Set TextBox Text
Please try:
HTH.
Code: Select all
string sScript;
sScript =
"this.addAnnot({Page: " +
curPage.ToString() +
", type: \"FreeText\", contents: \"12/10/2009 jstonis\", rect: [0, 0, 100, 100]})";
pdfActiveX.RunJavaScript(sScript, out sResult, 0, 0);
PDF-XChange Co. LTD (Project Developer)
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
-
- User
- Posts: 12
- Joined: Thu Mar 26, 2009 1:01 pm
Re: Programatically Set TextBox Text
That worked perfectly. Thank you!!
-
- Site Admin
- Posts: 5223
- Joined: Tue Jun 29, 2004 10:34 am
Re: Programatically Set TextBox Text
Pleased all is well 

If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.
Best regards
Tracker Support
http://www.tracker-software.com
Best regards
Tracker Support
http://www.tracker-software.com