Author: tilman
Date: Sun Jul  3 12:27:50 2016
New Revision: 1751153

URL: http://svn.apache.org/viewvc?rev=1751153&view=rev
Log:
PDFBOX-3408: Correct validation of Btn widget annotations for PDF/A-1

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
    
pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java
    pdfbox/branches/2.0/preflight/src/test/resources/expected_errors.txt

Modified: 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=1751153&r1=1751152&r2=1751153&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java 
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java 
Sun Jul  3 12:27:50 2016
@@ -539,6 +539,7 @@ public final class COSName extends COSBa
     public static final COSName W = new COSName("W");
     public static final COSName W2 = new COSName("W2");
     public static final COSName WHITE_POINT = new COSName("WhitePoint");
+    public static final COSName WIDGET = new COSName("Widget");
     public static final COSName WIDTH = new COSName("Width");
     public static final COSName WIDTHS = new COSName("Widths");
     public static final COSName WIN_ANSI_ENCODING = new 
COSName("WinAnsiEncoding");

Modified: 
pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java?rev=1751153&r1=1751152&r2=1751153&view=diff
==============================================================================
--- 
pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java
 (original)
+++ 
pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java
 Sun Jul  3 12:27:50 2016
@@ -126,6 +126,7 @@ public abstract class AnnotationValidato
      * DestOutputProfile of the OutputIntent dictionary.
      * 
      * @return true if the C field is present and the RGB profile is used.
+     * @throws org.apache.pdfbox.preflight.exception.ValidationException
      */
     protected boolean checkColors() throws ValidationException
     {
@@ -142,6 +143,7 @@ public abstract class AnnotationValidato
      * Search the RGB Profile in OutputIntents dictionaries
      * 
      * @return true if a rgb profile is found, false otherwise.
+     * @throws org.apache.pdfbox.preflight.exception.ValidationException
      */
     protected boolean searchRGBProfile() throws ValidationException
     {
@@ -162,6 +164,7 @@ public abstract class AnnotationValidato
      * If the AP content isn't valid, this method return false and updates the 
errors list.
      * 
      * @return the validation state of the AP content.
+     * @throws org.apache.pdfbox.preflight.exception.ValidationException
      */
     protected boolean checkAP() throws ValidationException
     {
@@ -185,21 +188,57 @@ public abstract class AnnotationValidato
             }
             else
             {
-                // the N entry must be a Stream (Dictionaries are forbidden)
                 COSBase apn = apDict.getItem(COSName.N);
-                if (!COSUtils.isStream(apn, cosDocument))
+                COSBase subtype = annotDictionary.getItem(COSName.SUBTYPE);
+                COSBase ft = annotDictionary.getItem(COSName.FT);
+                if (COSName.WIDGET.equals(subtype) && COSName.BTN.equals(ft))
                 {
-                    ctx.addValidationError(new 
ValidationError(ERROR_ANNOT_INVALID_AP_CONTENT,
-                            "The N Appearance must be a Stream"));
-                    return false;
+                    // TECHNICAL CORRIGENDUM 2 for ISO 19005-1:2005 (PDF/A-1) 
+                    // added a clause for Widget Annotations:
+                    // the value of the N key shall be an appearance 
subdictionary
+                    if (COSUtils.isStream(apn, cosDocument))
+                    {
+                        ctx.addValidationError(new 
ValidationError(ERROR_ANNOT_INVALID_AP_CONTENT,
+                                "The N Appearance of a Btn widget must not be 
a stream, but an appearance subdictionary"));
+                        // But validate it anyway, for 
isartor-6-3-4-t01-fail-f.pdf
+                        // Appearance stream is a XObjectForm, check it.
+                        ContextHelper.validateElement(ctx, new PDFormXObject(
+                                COSUtils.getAsStream(apn, cosDocument)),
+                                GRAPHIC_PROCESS);
+                        return false;
+                    }
+                    if (!COSUtils.isDictionary(apn, cosDocument))
+                    {
+                        ctx.addValidationError(new 
ValidationError(ERROR_ANNOT_INVALID_AP_CONTENT,
+                                "The N Appearance must be an appearance 
subdictionary"));
+                        return false;
+                    }
+                    COSDictionary apnDict = COSUtils.getAsDictionary(apn, 
cosDocument);
+                    for (COSBase val : apnDict.getValues())
+                    {
+                        // Appearance stream is a XObjectForm, check it.
+                        ContextHelper.validateElement(ctx, new PDFormXObject(
+                                COSUtils.getAsStream(val, cosDocument)),
+                                GRAPHIC_PROCESS);
+                    }
+                }
+                else
+                {
+                    // the N entry must be a stream (Dictionaries are 
forbidden)
+                    if (!COSUtils.isStream(apn, cosDocument))
+                    {
+                        ctx.addValidationError(new 
ValidationError(ERROR_ANNOT_INVALID_AP_CONTENT,
+                                "The N Appearance must be a Stream"));
+                        return false;
+                    }
+                    // Appearance stream is a XObjectForm, check it.
+                    ContextHelper.validateElement(ctx, new PDFormXObject(
+                            COSUtils.getAsStream(apn, cosDocument)),
+                            GRAPHIC_PROCESS);
                 }
-
-                // Appearance stream is a XObjectForm, check it.
-                ContextHelper.validateElement(ctx, new PDFormXObject(
-                        COSUtils.getAsStream(apn, cosDocument)),
-                        GRAPHIC_PROCESS);
             }
-        } // else ok, nothing to check,this field is optional
+        }
+        // else ok, nothing to check, this field is optional
         return true;
     }
 

Modified: pdfbox/branches/2.0/preflight/src/test/resources/expected_errors.txt
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/2.0/preflight/src/test/resources/expected_errors.txt?rev=1751153&r1=1751152&r2=1751153&view=diff
==============================================================================
--- pdfbox/branches/2.0/preflight/src/test/resources/expected_errors.txt 
(original)
+++ pdfbox/branches/2.0/preflight/src/test/resources/expected_errors.txt Sun 
Jul  3 12:27:50 2016
@@ -110,7 +110,9 @@ isartor-6-3-4-t01-fail-b.pdf=3.1.3
 isartor-6-3-4-t01-fail-c.pdf=3.1.3
 isartor-6-3-4-t01-fail-d.pdf=3.1.3
 isartor-6-3-4-t01-fail-e.pdf=3.1.3
-isartor-6-3-4-t01-fail-f.pdf=3.1.3
+# 5.3.1 check is not part of isartor, but N Appearance of a Btn widget must 
not be a stream, but an appearance subdictionary, see PDFBOX-3408
+# PDFTools validator agrees: "The appearance must have state dictionaries 
(subdictionaries to 'N')"
+isartor-6-3-4-t01-fail-f.pdf=3.1.3,5.3.1
 isartor-6-3-4-t01-fail-g.pdf=3.2.4 // Type3 Damage because the Type1 used as 
Resource isn't embedded 
 isartor-6-3-4-t01-fail-h.pdf=3.1.3
 isartor-6-3-5-t01-fail-a.pdf=3.3.1


Reply via email to