7 Replies Latest reply on Oct 26, 2014 3:51 PM by try67

    Save each page of a multi-page document as a separate file using spawned file names with javascript

    tdjohnson7700 Level 1

      Hello

       

      We are currently changing our hard-copy personnel files and converting them to pdf files.  We have scanned the entire file into one multi-page document.

       

      I am wanting to save each page (or groups of pages) as separate files.

       

      In order to facilitate this, I have duplicated field names--such as FirstName, LastName, EmpNo on each page.  This information should be static for the entire file.

       

      However--I also need information that will change for each individual "page" or document--such as TypeOfDoc, Date, etc.  I have used the Spawn fields using the overlay method on each of the pages in the document.  Then I went in and filled in the information for each page of the document--such as TypeOfDoc, DateOfDoc.

       

      Now I want to save each page of the document as a separate file using the field names as the file name.

       

      I first created an action that would split all the pages into separate files and save them into a folder.

       

      Then I want to save each file as a specific file name based on the information in the fields.

      My problem is obtaining the name of the spawned field name.  The rest of the field names I am not having a problem with.

       

      This is what I have so far to name the file.

       

      // Get the field value

      var oPage = this.pageNum;

      var fn = getField("P" + oPage + ".TEMPLATE.DateOfDoc").valueAsString + getField("FirstName").valueAsString + "-" + getField("LastName").valueAsString;

      // Specify the folder
      var fldr = "/n/Personnel/ScannedDocuments/NAMEDPAAS/";

      // Determine the full path
      var fp = fldr + fn +".pdf";

      // Save the file
      myTrustedSpecialTaskFunc(this, fp);

       

      This code is also accompanied with folder level scripts.

       

      My problem is obtaining the name of the spawned fields using javascript.  Each document has several pages--so I would like to obtain the field name through script.

       

      I receive the following error.

      TypeError: getField("P" + oPage + ".TEMPLATE.DATE") is null

       

      I think this is due to the fact that I have extracted all the pages as individual files.

       

      If I were to do the above, but not extract the pages first--I do not know how to just save one page at a time.

       

      Please help.  This is a massive project, and if we have to save each file individually, it will take a lot of time.

       

      I am a beginner, so any assistance is appreciated.

       

      Thank you