Skip to main content
Inspiring
July 27, 2017
Answered

Saving a Flat PDF w/ Field Filename & Current Date Time in new location

  • July 27, 2017
  • 1 reply
  • 6640 views

I am certain the below has been done 1,000s of times since this is a basic workflow activity.

I have read some other posts which go over the javascript folder level, the button event script, and LiveCycle Designer.

But I believe my confusion starts with my platform I am using to do this.

I know it is not hard, but I cannot figure out certain things that have become walls.

I am using Acrobat 11, Windows 7.

I can use Acrobat DC if required.

I believe LiveCycle Designer is no longer available or is being phased out.

But if required I can buy this license.

I do not know to what extent I can use Acrobat 11 to do what I want to do below.

This is the first area where I am confused.  I do not know if I even have the proper tools to do this.

What I want to accomplish:

I have about 20 pdf documents I will be converting to pdf Forms.

These are basically inspection and quality forms for what I do.

The forms will not change overtime, they really are basic.

Right now I fill out the forms by hand, turn them in at the end of the day, and then they are scanned and put in the correct place on my server.

I want to automate that process a little.

I do not need to input the data into a database or anything like that.

I want to create Forms that:

1. I can save each one on a shop computer and the guys can access them to fill them out.  I can manually set each computer up with the proper folder level javascripts.

2. I do not want the guys to be able to delete or revise the Form material.  So I was going to make the pdf Form file attributes read only.

3. I want the guys to open the file then fill out the form.  Once done they would click a button at the bottom of the page that does the below:

- flattens the pdf.  I do not want to save a fill-able form of the fill-able form.  I want a flat copy as if it were printed to the new location.

- saves the pdf to a specific location on our server.  This address does not change.

- create a filename that has one of the form fields (a serial number) + date/time .pdf  Bascially I want the filename to look like, 12345_Date-Time.pdf

The shop computers will have reader installed.  Will they need Acrobat 11?

Below is what I have figured out so far, but I cannot get it to work.  In the console I get "undefined" and nothing happens.

The below does not have anything to flatten the pdf before the "saveAs" function.  I figured I would have to add something to force all the fields to read only.

I am copying all this stuff from other posts, so please do not think I know what I am doing.  I am learning.

Javascript folder level

app.beginPriv();

// DateTime function

function myDateString() {

    return util.printd("yyyymmdd_HHMMss", new Date());

}

// SaveAs Function

var SaveForm = app.trustedFunction(function(vdoc) {

var myPath = "/C/Users/User1/Desktop/" this.getField("Serial No").value + "_" + myDateString() + ".pdf";

vdoc.saveAs(myPath);

app.endPriv();

// Do you really want to do this?

doc.closeDoc();

});

"Submit" Button javascript, triggered by mouse up event

This code has yet to be tested since I have only run the above in the console.

I may have to use (event.target) instead of (this).

SaveForm(this);

=========================

Am I on the right track?  Do I need to get LiveCycle Designer to do this correctly?

This topic has been closed for replies.
Correct answer Kortega

Move this line into the SaveForm function:

app.beginPriv();

And use the second version (with "this"), not the first one (with "event.target").


Revised my code to below as instructed, thank you!!!

function myDateString() {

    app.beginPriv();

    return util.printd("yyyymmdd_HHMMss", new Date());

    app.endPriv();

}

var FormSave = app.trustedFunction(function(vdoc) {

    app.beginPriv();

    var myPath = "/c/Users/User1/Desktop/" + vdoc.getField("Serial No").value + "_" + myDateString() + ".pdf";

    vdoc.saveAs(myPath);

    app.endPriv();

});

Using the below inside button, as mouse up.  The mouse enter command makes the event occur when the mouse moves over the button.  Don't want that to happen.  lol

FormSave(this);

I was getting this after I click the button and then run JS Console:

NotAllowedError: Security settings prevent access to this property or method.

Doc.saveAs:7:Field Button1:Mouse Enter

Which was weird because in my code at the folder level, I had nothing on line 7.

         C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Javascripts

Then I went to this location:

         C:\Users\User1\AppData\Roaming\Adobe\Acrobat\Privileged\11.0\Javascripts

where I had created the location from reading earlier posts.  Where earlier in the day I had put what is now an older copy of my javascript folder level file.

This had a line 7 that was old and not good.  I revised this file with the code above, and the system worked as required.

I even deleted the javascript from our original location:

         C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Javascripts

and the system still works as required.  Not sure why that is.

Starting to understand this a lot more now!

Thank you for helping!  I now want to find classes or some sort of instruction to start learning more about coding.

This was fun!

I will now add the code for making the fields read only before saving.

And will try to remove the button so the final saved document looks like a flat scanned document.

And also autoclose the original form once "submitted".

I will post my final code when complete for others to have in future.

Thank you...

I will rename "FormSave" & "myDateString" for security.

1 reply

try67
Community Expert
Community Expert
July 27, 2017

You don't need LCD. Yes, you're on the right track, although I see at least two errors in your folder-level script, both in this line:

var myPath = "/C/Users/User1/Desktop/" this.getField("Serial No").value + "_" + myDateString() + ".pdf";

Replace it with:

var myPath = "/C/Users/User1/Desktop/" + vdoc.getField("Serial No").value + "_" + myDateString() + ".pdf";

Also, change this line:

doc.closeDoc();

To:

vdoc.closeDoc();

After you do that restart the application and press the button again. What happens? Are there any error messages in the JS Console?
I suggest you test it in Acrobat first, and if it works use it in Reader.

And you can't flatten fields in Reader, but you can set them as read-only. If the saving part works correctly, we can implement that as well.

KortegaAuthor
Inspiring
July 28, 2017

Thank you for the help!

In JS Console, I keep getting "undefined", and nothing else happens.

Below is the code I am running in JS Console:

app.beginPriv();

function myDateString() {

    return util.printd("yyyymmdd_HHMMss", new Date());

}

var SaveForm = app.trustedFunction(function(vdoc) {

var myPath = "/C/Users/User1/Desktop/" + vdoc.getField("Serial No").value + "_" + myDateString() + ".pdf";

vdoc.saveAs(myPath);

app.endPriv();

vdoc.closeDoc();

});

I have verified the path, right now I basically am just testing and want the file to show up on my desktop.

Once I get it working I will direct it to my server.

I have verified the Field name is "Serial No".  In the form the field has "12345" entered into it.

I Preferences I have enabled:

- Enable Acdrobat Javascript

- Enable global object security policy

- Enable interactive console

- Use Acrobat Javascript Editor ( I have N++, but will use this once I get past this wall)

I do not know what else to verify.

To "flatten" I was going to make all the fields read only before saving the doc.

But was going to introduce that code once I get this working.

KortegaAuthor
Inspiring
July 28, 2017

Question:

Where is vdoc defined?

Is it defined in:

var SaveForm = app.trustedFunction(function(vdoc) {where the definition resides here}

If so, do I need to call SaveForm at the button event?

Even when running this in the JS Console?