You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2017/05/06 14:32:24 UTC
svn commit: r1794153 -
/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
Author: tilman
Date: Sat May 6 14:32:24 2017
New Revision: 1794153
URL: http://svn.apache.org/viewvc?rev=1794153&view=rev
Log:
PDFBOX-3738: remove /NeedAppearances when there are no previous fields because signature would be invisible in Adobe Reader
Modified:
pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java?rev=1794153&r1=1794152&r2=1794153&view=diff
==============================================================================
--- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java (original)
+++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java Sat May 6 14:32:24 2017
@@ -164,11 +164,31 @@ public class CreateVisibleSignature exte
signature = new PDSignature();
}
- // Optional: certify
+ // Optional: certify
if (accessPermissions == 0)
{
setMDPPermission(doc, signature, 2);
- }
+ }
+
+ PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
+ if (acroForm != null && acroForm.getNeedAppearances())
+ {
+ // PDFBOX-3738 NeedAppearances true results in visible signature becoming invisible
+ // with Adobe Reader
+ if (acroForm.getFields().isEmpty())
+ {
+ // we can safely delete it if there are no fields
+ acroForm.getCOSObject().removeItem(COSName.NEED_APPEARANCES);
+ // note that if you've set MDP permissions, the removal of this item
+ // may result in Adobe Reader claiming that the document has been changed.
+ // and/or that field content won't be displayed properly.
+ // ==> decide what you prefer and adjust your code accordingly.
+ }
+ else
+ {
+ System.out.println("/NeedAppearances is set, signature may be ignored by Adobe Reader");
+ }
+ }
// default filter
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);