Print Page | Close Window

Javascript - Where?

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2251
Printed Date: 13 Aug 25 at 5:25PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Javascript - Where?
Posted By: drsebast
Subject: Javascript - Where?
Date 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.
 



Replies:
Posted By: AndrewC
Date Posted: 02 May 12 at 3:35PM

These links might provide some help.

http://www.quickpdflibrary.com/faq/javascript-access-form-fields.php - http://www.quickpdflibrary.com/faq/javascript-access-form-fields.php
http://www.quickpdflibrary.com/faq/docjavascriptaction-function-need-help-urgent.php - http://www.quickpdflibrary.com/faq/docjavascriptaction-function-need-help-urgent.php
http://www.quickpdflibrary.com/faq/get-and-set-javascript-for-document-actions.php - http://www.quickpdflibrary.com/faq/get-and-set-javascript-for-document-actions.php

Andrew.


Posted By: drsebast
Date Posted: 02 May 12 at 3:52PM
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.


Posted By: AndrewC
Date Posted: 03 May 12 at 12:04PM
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; } "


Posted By: drsebast
Date Posted: 03 May 12 at 12:11PM
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.


Posted By: AndrewC
Date Posted: 04 May 12 at 10:05AM

Loading it as a string from a file would be the easiest and most manageable approach.

Andrew.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk