pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: workaround for PDF being considered modified if using setNeedAppreances(true)
Date Thu, 14 Sep 2017 21:22:50 GMT
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: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message