Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
![]() |
Javascript - Where? |
Post Reply ![]() |
Author | |
drsebast ![]() Beginner ![]() Joined: 02 May 12 Location: Ohio Status: Offline Points: 3 |
![]() ![]() ![]() ![]() ![]() Posted: 02 May 12 at 12:57PM |
I have created pdf map pages from ESRI's ArcMap that contain multiple layers. I have created pushbuttons (5 formfield checkboxs) on the legend items. I want to attach javascript code (which I already have) to the each button which will toggle the visibilityof the legend layer (OCG) item. This allows users to quickly toggle these 5 OCGs on and off. Easier than using the layer menu because the script also toggles the labels for the OCG.
I have 476 map pages to update with this code. I already have the code for entering other fields in place on these pages but I am stuck with the javascript. I have gotton to where I am supposed to enter the javascript in the function (FormFieldJavaScriptAction for example). My code is multiline. How do I put it in this or other functions? Can I enter a reference to a text file that has the code so that it loads the file and runs the script when clicked? Do I have to somehow include the code in the pdf? If so, how? Basic code examples would be a great help. Thanks in advance. |
|
![]() |
|
AndrewC ![]() Moderator Group ![]() ![]() Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
![]() ![]() ![]() ![]() ![]() |
![]() |
|
drsebast ![]() Beginner ![]() Joined: 02 May 12 Location: Ohio Status: Offline Points: 3 |
![]() ![]() ![]() ![]() ![]() |
I have already checked those out, but they don't answer my basic question.
For example, when entering the function FormFieldJavaScriptAction it calls for "Javascript as String" as a parameter. One of the scripts I want to run when this button is pushed is: var docOCGs = this.getOCGs(); for (var x=0; x < docOCGs.length; x++) { if(docOCGs[x].name == "City") { docOCGs[x].state = !docOCGs[x].state; } if(docOCGs[x].name == "City - Default") { docOCGs[x].state = !docOCGs[x].state; } } This toggles the City OCG and its label OCG. I can't enter this as the parameter because of the length and multilines. How do I actually enter the above javascript into the pdf so that I can use this function to run it? I can do it from a pdf editor one file at a time, but that isn't practical. |
|
![]() |
|
AndrewC ![]() Moderator Group ![]() ![]() Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
![]() ![]() ![]() ![]() ![]() |
You code can easily be added as a string.
string s = "var docOCGs = this.getOCGs();\n" + "for (var x=0; x < docOCGs.length; x++)\n" +{\n" + if(docOCGs[x].name == "City") \n" + {\n" + docOCGs[x].state = !docOCGs[x].state;\n" + }\n" + if(docOCGs[x].name == "City - Default")\n" + {\n" + docOCGs[x].state = !docOCGs[x].state;\n" + }\n" + } \n"; Just pass this string to the FormFieldJavaScriptAction. You could even put all of the code on one line and it would run fine. I have already checked those out, but they don't answer my basic question.
For example, when entering the function FormFieldJavaScriptAction it calls for "Javascript as String" as a parameter. One of the scripts I want to run when this button is pushed is: string js = "var docOCGs = this.getOCGs(); for (var x=0; x < docOCGs.length; x++) { if(docOCGs[x].name == "City") { docOCGs[x].state = !docOCGs[x].state; } if(docOCGs[x].name == "City - Default") { docOCGs[x].state = !docOCGs[x].state; } } " |
|
![]() |
|
drsebast ![]() Beginner ![]() Joined: 02 May 12 Location: Ohio Status: Offline Points: 3 |
![]() ![]() ![]() ![]() ![]() |
Thank you for the idea and response.
I had just stumbled upon that approach yesterday and it does work. It does seem clumsy and that there should be an easier way, but it works. I may attempt to try reading the scripts from a file as a string just for the heck of it. This would allow for much easier editing of the java and longer scripts. Thanks again. |
|
![]() |
|
AndrewC ![]() Moderator Group ![]() ![]() Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
![]() ![]() ![]() ![]() ![]() |
Andrew.
|
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store