0

Using Adobe Acrobat Pro DC, I need certain form fields to clear their values when the document opens. Here's one line I've placed in Tools > JavaScript > Document JavaScripts:

getField("Patient").value = "";

However, that doesn't run when the PDF is opened. (It works when called from a Document Action.)

Thanks

2 Answers 2

2

The exact moment when a document-level script is executed is not known, and that means that a field may not yet have been created when the script runs.

In my experience, when it comes to set field values when the document opens, it is much safer to use the pageOpen event of the page at which the document opens.

Note: when you have a multi-page document, you will need to make sure that this piece of code gets executed only once; this is done in a way like this:

In a document-level script define:

var loaded = 0 ;

In the pageOpen script have this construct:

if (loaded < 1) {
// execute code when document opens
loaded++ ;
} else {
// execute code when returning to the page
}

And that takes care of the situation.

Sign up to request clarification or add additional context in comments.

Comments

0

Use this tool to Inject a JavaScript file into a PDF file.

Demonstration how to solve the problem (essential part): To do this you will need an existing PDF file, and a ".js" file which contains the commands you would like to run (in the original question) when the document is opened. I use this to create PDFs with some active code in there that I can email to customers, or download through their proxies, to check for the JavaScript being removed or blocked. When you open the produced PDF with the JavaScript injected in Adobe you should see your code execute. Mileage varys in other viewers and for certain Edge in Windows 10 does not execute.

https://github.com/cornerpirate/JS2PDFInjector

1 Comment

I'm not an Acrobat expert, but tested this tool with a simple PDF and worked. Secured, you mean password protected?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.