Skip to main content
October 27, 2016
Question

Dynamic Date On Printouts - Saving Routine

  • October 27, 2016
  • 55 replies
  • 7407 views

Hello everybody.

To add a field with a dynamic date + "expiry date" i used this script:

var inch = 72;

for (var p = 0; p < this.numPages; p++) {

var aRect = this.getPageBox( {nPage: p} );

aRect[1] = .5*inch;

aRect[3] = aRect[1] - 24; // and 24 points high

var f = this.addField("PrintField", "text", p, aRect )

f.delay = true;

f.textSize = 10;

f.textFont = font.Cour;

f.textColor = color.black;

f.alignment = "center";

f.readonly = true;

f.display = display.noView;

f.delay = false;

}

var d = new Date();

d.setDate(d.getDate()+3);

this.getField("PrintField").value = "Dokument gültig bis " + util.printd("dd.mmm.yyyy", d);

this.setAction("WillPrint", myWillPrintScript);

It works pretty well, but i have an issue about the need to save the file each time i print it.

Is there a way to avoid the saving (as no changes are made to the document...) or as a workaround

to automize the saving-procedure?

Another thing, is there a way to forbid users to make changes to an implemented java script?

Thanks in advance,

Otto

This topic has been closed for replies.

55 replies

Legend
October 31, 2016

I think you may have been ignoring the parts of replies you didn't understand. But that leaves us, trying to help, in an impossible position, because you say you've done what we said. For instance, I said twice that you need to save and restore this.dirty , and you say you've done it all. Ok, what code did you add to do that and EXACTLY WHERE did you put it? Or did you ignore that part?

Legend
October 31, 2016

That would be a lot of work, please share a file.

October 31, 2016
Bernd Alheit
Community Expert
Community Expert
October 31, 2016

You adds the whole code to the Document Will Print action.

Don't do this. You didn't read our replies.

Legend
October 28, 2016

Yes, there are many other ways you could have added a script. For example you could have used different actions. You could have attached the code to a button, or a bookmark. You could have made a script to be executed on document open [this is more what I was expecting, it's the most common way to do this sort of thing, but not necessarily the best]. You could have added a startup script. You could have had a mixture (like startup script to define a procedure, executed by an action or button)... you could have run it in the console, or a batch action, or via Visual Basic. Privileges and contexts can vary with how the script is run... so details matter.

To summarize what seems to have emerged as the advice.

1. If you correctly set the dirty property for the document you WILL stop a save prompt for a normal file.

2. This may seriously confuse the user if they had already changed the document and expected a save prompt, so your code would be better if you save and restore the dirty property instead of just clearing it.

3. You can set security but must allow form filling.

4. You need to check JavaScript console for errors and you need to look at your printout each time!

October 28, 2016

Test Screen Name schrieb:

To summarize what seems to have emerged as the advice.

1. If you correctly set the dirty property for the document you WILL stop a save prompt for a normal file.

2. This may seriously confuse the user if they had already changed the document and expected a save prompt, so your code would be better if you save and restore the dirty property instead of just clearing it.

3. You can set security but must allow form filling.

4. You need to check JavaScript console for errors and you need to look at your printout each time!

1. as I repeatedly stated, I havo no idea how "correctly" looks like in Java

     Providing me the correct pieces is very nice, but it often makes it more complicated in the end...

2. the users should/must not make any changes to the documents. If there is a change required they are made in the respective word      document with revision and change control and then a pdf file is created from there. so the pdf-file is to be static.

3. If you look at the screen shot above you see I did that...not successful.

4. JavaScript console: The box where I enter the code after clicking on "Edit"?

Knowing something better and sharing this knowledge are often two different pairs of boots...

Bernd Alheit
Community Expert
Community Expert
October 28, 2016

You will get the JavaScript console (debugger) when you type ctrl+j

Legend
October 28, 2016

We understand your requirement, and have posted the solutions, I believe. I don't think we will gain by repeating our answers. You have still not told us WHERE you put this script. You just say "Add script". Please give details.

October 28, 2016

Test Screen Name schrieb:

You have still not told us WHERE you put this script. You just say "Add script". Please give details.

Inside a pdf document.

Tools > JavaScript >Set Document Actions >Document Will Print > Edit

There I enter the code and see if it does what I expect it to do.

As I wrote above.

Are there other ways to "add a script" in a PDF file?

Legend
October 27, 2016

That's surprising if you didn't add a reference to this.dirty. Unless you set too much security, so your script can't run.

October 28, 2016

Good morning,

I removed this.dirty from the script, as it did not inhibit the save-prompt.

When I set the security level to "print only" there is no more save-prompt popping up.

But it is as i feared...the date is not updated.

Can I allow a Java script inside a protected document to make changes?

And if so, how?

Thanks again,

Otto

Bernd Alheit
Community Expert
Community Expert
October 28, 2016

You must allow form filling.

Bernd Alheit
Community Expert
Community Expert
October 27, 2016

At the end of your script add following line:

this.dirty = false;

This will mark the document as not modified.

October 27, 2016

Hallo Bernd,

it keeps asking me to save...

As the date in the field is actually changing day by day i might have to live with it.

@Test Screen Name

Where exactly do I find these settings? What will I have to modify?

Thanx!

Otto

Legend
October 27, 2016

I think working with this.dirty is a good idea, though better to save and restore so that if the user has actually changed it, then they still get a prompt.

Security should be well covered in the Help files, but look under File > Properties and the Security tab. You would set Password Security, but no Open Password.

Legend
October 27, 2016

Is thus script run each time the document opens? If so, it really is changing the document. Anything that changes a field changes the PDF.

You you can set document security to protect forms from editing in Acrobat, while allowing printing.