Document-level Javascript as Object

I created a document level script called Utility.
I want to create methods within this script rather than coding each one separately.
function Utility()
this.getFormattedDateOnly=function(pDate) {
  if (typeof pDate == "undefined") {
    pDate = new Date();
  var retval = util.printd("m/dd/yyyy",pDate);
  return retval;
this.getFldsOnPagenum = function(pPageNum, pDoc) {
  /* returns an array of the form fields who are on or start on a page */
  /* zero based return ; however pPageNum is 1 thru numPages, not 0 -> numPages-1 */
  var currPage;
  var currFld;
  var cnt = -1;
  var ARflds = [];
CPR("# flds=" + pDoc.numFields+" Type of pDoc:"+ (typeof pDoc));
  for (var i = 0; i < pDoc.numFields; i++) {
    currFld = pDoc.getNthFieldName(i);
    if (typeof currFld.page == "number") {
CPR("page="+(1*currFld.page+1));
      if ((1*currFld.page+1) == pPageNum) {
        cnt++;
        ARflds.length = cnt + 1;
        ARflds[cnt] = currFld;
CPR("\n cnt="+cnt);
    } else if ((1*currFld.page[0]+1) == pPageNum) {
      cnt++;
      ARflds.length = cnt + 1;
      ARflds[cnt] = currFld;
  return ARflds;
var MyUtil = new Utility();
This is all working fine with the following exceptions:
1) the methods are not being registered in the Javascript hierarchy listing.
That's annoying.
2) "This" is not recognized at the document level....I must pass it as a parameter (pDoc).
I thought that was strange...I could see it if were at the folder level.
It appears the document object is out-of-scope !!
3) currFld = pDoc.getNthFieldName(i);
The above is failing....sending back a "currFld is undefined" error.
I don't see the problem....very strange IMHO.
When I call the getNthFieldName function from the console....no problem.
What am I doing wrong in the definition here ?
It appears that what I did has Acrobat functions and document properties out-of-scope.

I think this would work if you could make the document object a member of the Object being created.
To do that, a constructor needs to be invoked so that it can instantiate a public property of the Object.
var MyUtil = new Utility(this);
inside of Utility I would have:
this.oPDFdoc =  this;
thereby transferring a reference to the entire PDF document to my Object.
Getting this to work would eliminate the need for all of the document-level javascript references.

Similar Messages

  • Document Level Javascript

    Is it possible to create document level javascript ?
    I would like to create a function that I would be able to call in events.
    And is it possible to store an object (like an ADBC connection) at the document level to access it where I want ?
    Thanks.
    Laurent

    There is something called "script object". The script object is an object that you can use to store JavaScript functions and values separately from any particular form object. Typically you use the script object to create custom functions and methods that you want to use as part of scripts in many locations on your form. This technique reduce the overall amount of scripting required to perform repetitive actions.
    To add a new script object to your form:
    - Create a new form or open an existing form.
    - In the Hierarchy palette, right-click either a form-level object or a subform-level object and select Insert Script Object.
    - You can rename your script object (optional) by right-click the script object and select Rename Object.

  • Document-level javascript quandry

    Ok, completely clueless newbie here whose only coding experience is Access VBA…from a few years ago. Need to write up some Javascript to make this work – that was a month’s worth of a migraine.  I ask for your patience, and would like to ask for forgiveness in advance for any headaches I induce while you try to figure out my problem(s).  Also, I’m not sure how to copy paste images or code examples, but I will do my best.
    So, basic premise:  make a drop-down combo box that will populate another combo box based on whatever was selected in the first box – in this case, 31 items in the ‘Inventory Parts Used’ list, and a total of 427 respective sizes in the other list. 
    YES, I’ve already looked at that http://acrobatusers.com/tutorials/js_list_combo_livecycle1 example, and followed it closely.  Took me forever, but I somehow got it to work. Was very happy.  Only thing I couldn’t figure out was the export value b/c mine wasn’t a number.  But I solved that by putting the CodeID and respective PartSize together (ex: 4-inch Fire Hydrant would show up as "FH-01:  4"). Anyways, I selected that working row and choose the “Place Multiple Fields” option times 15 rows.  Still working.  I’m dancing a jig. Then I tried to check on the code: 
    “Text cannot be displayed in full by the Edit Dialog.  Please use an External Editor.” 
    Uh… So I deleted a row at a time until I could see what my limit was.  I had to pare down 15 rows to a measly 3 rows.  Took me a while but I was able to see where the problem was.  Instead of being written into the Document-Level JS, my array was tied to the first combo box’s Keystroke event on the Field Level.  So when I multiplied the rows, that humongous list essentially had diarrhea.
    I’ve tried to delete that header and keep it to Document Level.   It basically ignored me and keep those lines.  When I did manage to make the <Document-Level> on top, it just didn’t work.
    (    //<AcroForm>
    //<ACRO_source>Row0.InvPart:Keystroke</ACRO_source>
    //<ACRO_script>
    /*********** belongs to: AcroForm:Row0.InvPart:Keystroke ***********/    )
    I’ve searched other forums about the Document-level…. I swear I read a lot of forums that said using Advanced>Document Processing>Set Document Actions>Edit All was ok. Clearly it’s not ok, especially after I found this forum: http://answers.acrobatusers.com/Where-I-enter-document-level-javascript-adding-FormRouter- Calendar-q55527.aspx. 
    So I guess my question(s) is this:  IS that “Edit Document Javascripts” really necessary?  B/c I’ve looked and I don’t have it. I’m using Adobe Acrobat 9 Standard, ver 9.5.5 (and I’m using Windows XP Pro ver 2002 , if that matters).  Is this JS editor only available to the Pro version?  Would it really be a bad thing to just leave it alone as a keystroke event (aside from the unwieldy large, duplicated codes it vomits as a result)? Or maybe, is there a way to code a new row on instead?  I remember seeing an example where you can add more lines as needed, but I can’t for the life of me find it again.
    Thank you in advance for all your assistance.

    * Huh....it just figures... right after I finally give up and post up a question, I would find the answer. =_=;; http://forums.adobe.com/message/4727325#4727325. 
    So, Standard version apparently doesn't have that exalted “Edit Document Javascripts”.  Apparently a way around it is using the Page Open event.  Well, it works - the massive array only shows up once in the editor, and the multiple rows each call the function instead.  Nice. 
    Well, I will leave this up in case someone else can use the reference.  Thanks to anyone who read this and was going to answer me. =)
    Don't suppose anyone knows how to create a code to add new rows instead of having 15 rows straight off the bat?  Or should I make a new post for that?

  • How do you do document level javascript docopen in acrobat pro lifecycle designer

    You used to be able to do document level javascripts like document open and process parameters from a url to prefill a pdf file. 
    How do you do that in acrobat pro 10 or life cycle designer?
    Thanks in advance
    Dean-O

    Should be the same but it isn't. I have included a screenshot of my tools choices in both my Mac and PC versions - they are totally different.
    Mac version
    PC Version

  • Integration of javascript libraries with Acrobat Document Level Javascript

    I have a requirement to build a custom SOAP message and process a PDF document as a SOAP attachment sent to a specific endpoint.
    Document level javascript presents a tool that when coupled with a third party javascript library could be used to capture the PDF document and send it as a custom SOAP message built entirely with Javascript.
    Does document level javascript allow for integration with third party libraries like Dojo or the like?
    Any examples available of document level javascript including known third party javascript/ajax libraries?

    Ajax and other JS libraries can't really be used in Acrobat. You can load them, of course, but they're built for JS that runs in web-browsers and will not be of much use in a PDF.

  • Multiple document level javascripts

    Hi everyone,
    I've just created a document level javascript that assesses the viewer's version of acrobat. I also need to create another document level javascript that will open a popup menu when the document is opened, providing instructions on how to fill out the form. Since there will be two document level javascripts happening at the same time, ie. when the document opens, I wondered if someone could tell me if this is going to cause some conflict. I mean the second javascript that creates the instructions popup is going to happen for everyone when the document opens but the first viewer version javascript will only be triggered if the viewer's version is less than 7.5. So I wondered if someone opens the file and both javascripts are triggered, will this cause an error, or will both popup boxes appear on the screen at one time. I can't actually test this myself since my version of acrobat is current.
    Appreciate any advice.

    They will not lauch in parallel, but one after the other, probably based on their names.
    My suggestion to you is to just combine the two into a single script, each in its own function, and then run them in the order you prefer.

  • Document Level JavaScript to turn off caching for a PDF?

    I have been trying to find a way to ensure that a fillable PDF leaves no trace of itself on a computer that was used to open it. For example, if a user acceses a fillable PDF via browser or Reader, once they are done and have closed the browser or Reader, I want no trace of the information to remain in any cache on that machine. We don't want to require our users to try to control cache via settings in Reader, so I have been trying to find other ways to do this.
    I came across the following comment from GKaiseril in another thread - is this a way for a PDF to control its own caching? Any details or alternative approaches would be welcome!
    GKaiseril
    Re: Metadata - Can't remove
     You can also use document level JavaScirpts to turn off the auto complete and caching for a given PDF.

    Version 9 and 10 of Reader do not cache form data in a temporary FDF as previous version may have. The nocache document property it not even documented in the latest Acrobat JavaScript reference. If you're concerned about previous versions, you can use set the nocache document property at run-time, but users can disable JavaScript, so that approach is no guarantee.
    For information on controlling autocomplete, see: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.407.html

  • Acrobat crashed and i lost all document level javascript

    Hi, while working with acrobat professional 9 i got an error messages and acrobat crashed. I had 300 lines of javascript code on document level and after i reopened the pdf document it wasn't there even though i had been saving the document many time before the error ccurred. Any idea how can i retrieve that javascript back? And why did it all disappear?

    Thank you very much for your reply but I already tried this and it didn't work. I will try to review all the sites visited over several months of which these tabs were accumulated . What a big hassle. I do notice that Firefox has crashed fairly often . Its just in the past I was able to retrieve my open tabs. I may go back to Internet Explorer. Thanks again for you help.

  • How to protect document level javascript against modification?

    Hi,
    Does Adobe Acrobat provide a possibility to password protect deactivation of the javascript code present in the pdf documentation?
    It seems that 3rd party tools, like PDFill or CutePDF can not password protect the document properly and it is trivial to deactivate the code by putting a new code inside, even if the document is master password protected agains modifications.
    Thanks for any information.

    There's nothing to protect against the determined. If you have critical security functionality, embedding it at client end is not the way forward.

  • Document level scripting

    I have read about document level scripting -
    This is a nice feature - since it allows a certain level of generalization rather that writing a scriptlet for each objects events.
    I am using Live cycle designer 8.2
    How can I create a document level javascript function ?  i can't see how to do it .
    I am familiar with java scripting and have been scripting for a number of events but i would really like to be able to have a callable function that I pass certain parmeters to for processing.
    please indicate how I can do this .
    Thanks

    You should post this in the LiveCycle Designer forum here, if you haven't already.

  • Error Running Doc-Level JavaScript from VBS

    I have the document level javascript function in my PDF document "FillForm()", (see code below).  When I run my VBS code, (see code below) I get the error:  "Run-time Error '438': Object doesn't support this property or method." on the "jso.FillForm" line.  I can execute 'jso.console.Show' without a problem.  What am I doing wrong?  (Oh, and it has to be a document level funtion, and not a folder level function.  And once I get this working, I'll be passing parameters.  I'm using a stripped down function just to get this to work).
    DOCUMENT JAVASCRIPT
    //<Document-Level>
    //<ACRO_source>FillForm</ACRO_source>
    //<ACRO_script>
    /*********** belongs to: Document-Level:FillForm ***********/
    function FillForm()
    var textHolder;
    textHolder = this.getField("dorReturnAddress");
    textHolder.value = "dorReturnAddress";
    textHolder = this.getField("attn");
    textHolder.value = "attn";
    //</ACRO_script>
    //</Document-Level>
    VBS CODE
      Dim wAcro As Acrobat.AcroApp
      Dim dAcro As Acrobat.AcroPDDoc
      Dim jso As Object
      Set wAcro = CreateObject("AcroExch.App")
      wAcro.Show
      Set dAcro = CreateObject("AcroExch.PDDoc")
      dAcro.Open (ThisDocument.Path & "\" & "Worksheet - Template.pdf")
      Set jso = dAcro.GetJSObject
      jso.FillForm
    - Thanks in Advance!

    You can use the function ExecuteThisJavascript. Read more here:
    http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=16431

  • Is there a way to respond to Doc/Open events from a folder level javascript?

    I'm wondering if there's a way to respond to Doc/Open events from a folder level javascript. If not, is there a way to programatically add a Document javascript to a PDF upon/after export from InDesign?
    Thanks-
    Jeremy

    Bernd,
    Thanks for your reply. I take what you write to mean that I can add a document-level javascript manually once the PDF is exported. But this is what I'm trying to avoid.
    Ideally, I want to respond to Doc/Open events from a folder level javascript, but I'm not sure if/how I can make an event listener with Acrobat JS. If I can't do that, then I'm looking for a way to programatically add a Document level javascript upon export from InDesign - not manually within Acrobat, once the PDF is created.
    Any thoughts?

  • Unable to update rating (rating column) on host document using JavaScript Object Model API inside sharepoint hosted apps

    Hi Everyone,
    We are developing SharePoint hosted apps for Office 365, for that we are going
    to implement document rating functionality inside Sharepoint app. The host web contain document library (“Documents”) and from apps we need to rate each document. The rating functionality working fine with CQWP in team site  using
    JavaScript Object Model API.
    But the same code is not working inside apps and giving error:-
    If we are using app context than error will be:-
    "List does not exist.
    The page you selected contains a list that does not exist.  It may have been deleted by another user."
    And for Host context than error will be:-
    "Unexpected response data from server."
    Please help on this
    Please see below code..
    'use strict';
    var web, list, listItems, hostUrl, videoId, output = "";
    var videoLibrary = "Documents";
    var context, currentContext;
    var lists, listID;
    var list, parentContext;
    var scriptbase;
    (function () {
        // This code runs when the DOM is ready and creates a context object which is 
        // needed to use the SharePoint object model
        $(document).ready(function () {
            hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
            context = SP.ClientContext.get_current();      
            SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
        function sharePointReady() {
            scriptbase = hostUrl + "/_layouts/15/";
            // Load the js files and continue to the successHandler
            $.getScript(scriptbase + "SP.Runtime.js", function () {
                $.getScript(scriptbase + "SP.js", function () {
                    $.getScript(scriptbase + "SP.Core.js", function () {
                        $.getScript(scriptbase + "reputation.js", function () {
                            $.getScript(scriptbase + "sp.requestexecutor.js", execCrossDomainRequest);
        //Query list from hostweb
        function execCrossDomainRequest() {       
            //Load the list from hostweb
            parentContext = new SP.AppContextSite(context, hostUrl);
            web = parentContext.get_web();
            list = web.get_lists().getByTitle(videoLibrary);
            context.load(list, 'Title', 'Id');
            var camlQuery = new SP.CamlQuery();
            camlQuery.set_viewXml('<View><Query><OrderBy><FieldRef Name="Modified" Ascending="FALSE"/></OrderBy></Query><RowLimit>1</RowLimit></View>');
            listItems = list.getItems(camlQuery);        
            context.load(listItems);
            context.executeQueryAsync(onQuerySucceeded, onQueryFailed);
        //Process the image library
        function onQuerySucceeded() {       
            var lstID = list.get_id();
            var ctx = new SP.ClientContext(hostUrl);       
            var ratingValue = 4;
            EnsureScriptFunc('reputation.js', 'Microsoft.Office.Server.ReputationModel.Reputation', function() {      
            Microsoft.Office.Server.ReputationModel.Reputation.setRating(ctx, lstID, 1, ratingValue);       
            ctx.executeQueryAsync(RatingSuccess, RatingFailure);
        function onQueryFailed(sender, args) {
            alert('Failed' + args.get_message());
        function failed(sender, args) {
            alert("failed because:" + args.get_message());
        function RatingSuccess() {
            alert('rating set');
            //displaystar();
        function RatingFailure(sender, args) {
            alert('Rating failed : : ' + args.get_message());
        //Gets the query string paramter
        function getQueryStringParameter(paramToRetrieve) {
            var params;
            params = document.URL.split("?")[1].split("&");
            for (var i = 0; i < params.length; i = i + 1) {
                var singleParam = params[i].split("=");
                if (singleParam[0] == paramToRetrieve) return singleParam[1];
    Thanks & Regards
    Sanjay 
    Thank you in advance! :-)
          

    Hi,
    According to your post, my understanding is that you want to update list column in SharePoint hosted apps using JavaScript Client Object Model.
    Based on the error message, it seems not retrieve the list object in context. I suggest you debug the code step by step using Internet Explorer Developer Tools to
    find the problem.
    Here are some demos about using JavaScript Client Object Model in SharePoint hosted app:
    http://blogs.msdn.com/b/officeapps/archive/2012/09/04/using-the-javascript-object-model-jsom-in-apps-for-sharepoint.aspx
    http://sharepoint.stackexchange.com/questions/55334/how-to-access-list-in-sharepoint-hosted-app
    http://www.dotnetcurry.com/showarticle.aspx?ID=1028
    Best regards
    Zhengyu Guo
    TechNet Community Support

  • Add application and document level events using javascript

    Hi All,
    I need to do some validation in the preprint event of the pdf document. There are samples available using the UI and adding the script in the script dialog, but my requirement is that i need to map the 'preprint' event and event handler to the pdf document using pure javascript code without the UI. Any help would be greatly helpful. Thanks in advance.
    Regards,
    Charan

    You can write a document-level function into the actions handlers using the doc.setAction() method from a folder-level script, but one folder-level script cannot create another.
    Suppose you have a folder-level function triggered by a menu item, and it has collected a reference to the active document as oDoc:
    var myScript = 'console.println("I am about to be printed and I have " + this.numPages + " pages" );';
    oDoc.setAction("WillPrint",myScript);

  • Adobe javascript include "this.saveas" into the pdf document level

    Hello,
    in some posts i read that if i certify a pdf, i would be able to include doc.saveas into the pdf document level. 
    Can anybody tell me what kind of cerify i'd need and how to have it done to make the saveas work from client side?
    thanks alot

    When you use the saveAs method with code inside the PDF, do not place it in a trusted function or use app.beginPriv/app.EndPriv. You have to confirm that the certificate is in your list of trusted certificates and that it is trusted to allow execution of high privilege JavaScript. Be sure to test the document with Reader and validate the signature before attempting to execute the code. There is a preference that controls whether signatures are validated when a document is opened. I would recommend setting this preference.
    I would suggest testing it with Reader.

Maybe you are looking for

  • What exactly are unscaledWidth and unscaledHeight in mobile item renderers?

    Hello, What exactly are unscaledWidth and unscaledHeight that get passed to the measure() method for a mobile item renderer? I am guessing renderers start at  "default" width and height (so unscaled) which get scaled based on DPI. Is that it? Thank y

  • Solaris Cluster 3.3 on VMware ESX 4.1

    Hi there, I am trying to setup Solaris Cluster 3.3 on Vmware ESX 4.1 My first question is: Is there anyone out there setted up Solaris Cluster on vmware accross boxes? My tools: Solaris 10 U9 x64 Solaris Cluster 3.3 Vmware ESX 4.1 HP DL 380 G7 HP P20

  • How to change active partition?

    Hi experts, I have disk D which contains OS windows 7 and not in active, but my another disk E is in active with 100% free space.so, how can i change active partition from E to D ? please help me  

  • Role and groups ?

    What is the difference between roles and groups in Identity Server

  • Dynamic routing through VPN on ASA

    I have an environment with multiple remote offices connecting to the an ASA at the core. Currently we create seperate IPSec tunnels to each subnet that the remote office needs to connect to. We would like to enable dynamic routing to allow access to