pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Grosso <gary.gro...@oberontech.com>
Subject RE: workaround for PDF being considered modified if using setNeedAppreances(true)
Date Fri, 15 Sep 2017 15:16:24 GMT
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:THausherr@t-online.de] 
Sent: Thursday, September 14, 2017 5:23 PM
To: users@pdfbox.apache.org
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: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message