Yes, just tried that, and I get the prompt to save changes before closing, which is odd since I'm not even closing the file that I'm aware of. I guess it closes and reopens behind the scenes.
Once that is done, it seems to behave as desired (doesn't prompt if it is subsequently really closed, unless there have been changes made in which case it does prompt). Gary -----Original Message----- From: Tilman Hausherr [mailto:[email protected]] Sent: Sunday, September 17, 2017 7:08 AM To: [email protected] Subject: Re: workaround for PDF being considered modified if using setNeedAppreances(true) I tried this code: PDActionJavaScript openAction = new PDActionJavaScript(); openAction.setAction("this.dirty = false;"); document.getDocumentCatalog().setOpenAction(openAction); However I have set Adobe Reader to disable JS by default. If I enable it on the yellow bar the saving question dialog comes anyway. But if javascript is enabled for that file, then even if the file is regenerated, then it works, i.e. it won't ask for saving if no changes have been made. If changes have been made then it asks. Tilman Am 15.09.2017 um 17:16 schrieb Gary Grosso: > I also had concerns about the scope of pdfDocOpened. But it seems to work. I > would welcome input as to possible pitfalls or improvements. > > Also, using an OpenAction in the document catalog sounds like a good > idea. I was already supporting the PO action, so it was easier, that's all. > > > Gary > > > > -----Original Message----- > From: Tilman Hausherr [mailto:[email protected]] > Sent: Thursday, September 14, 2017 5:23 PM > To: [email protected] > Subject: Re: workaround for PDF being considered modified if using > setNeedAppreances(true) > > I haven't had the time to test it, but this javascript code > > {this.dirty = false; var pdfDocOpened = true;} > > > doesn't this mean that you're setting the local variable "pdfDocOpened"? > > And this: > > "var isDirty = this.dirty;" > > ... > > "if (!isDirty) {this.dirty = false;}" > > > so you're setting the global dirty to false if it was false before. > > If this really works, I'd like to make an example out of this so that people > who set needAppearances to true can avoid the dialogbox if they have changed > nothing. I wonder if this can be used as an OpenAction in the document > catalog. > > Tilman > > > Am 11.09.2017 um 03:40 schrieb Gary Grosso: >> When using PDAcroForm.setNeedAppearances(true) to set a signal in the PDF >> file that Reader/Acrobat should provide missing appearances, if a user opens >> that PDF file and goes to quit, even if they have made no changes >> (manually), they are prompted to save the file, because of the appearance >> modifications which have been done automatically. >> >> I found that I could insert a hidden textbox with a bit of JavaScript to >> avoid this: >> >> PDActionJavaScript jsAction = new PDActionJavaScript(); >> jsAction.setAction("if (typeof(pdfDocOpened) == 'undefined') >> {this.dirty = false; var pdfDocOpened = true;}"); >> annotationActions.setPO(jsAction); >> widget.setActions(annotationActions); >> >> I also had to augment some code I am using to allow a user to specify a date >> textfield as "current" to maintain the modified/unmodified status: >> >> PDActionJavaScript jsPageOpenAction = new PDActionJavaScript(); >> String javaScript = "var isDirty = this.dirty;" >> + "var now = util.printd('mm/dd/yyyy', new Date());" >> + "var oField = this.getField('" + nameStr + "');" >> + "oField.value = now;" >> + "if (!isDirty) {this.dirty = false;}"; >> jsPageOpenAction.setAction(javaScript); >> annotationActions.setPO(jsPageOpenAction); >> >> >> Gary >> >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

