Skip to content

Commit 10cc267

Browse files
committed
Get rid of Contents check for non-textual annotations
DEVSIX-7762
1 parent 0c32b7a commit 10cc267

File tree

8 files changed

+54
-30
lines changed

8 files changed

+54
-30
lines changed

pdfa/src/main/java/com/itextpdf/pdfa/checker/PdfA1Checker.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public class PdfA1Checker extends PdfAChecker {
112112
PdfName.Saturation)));
113113
private static final int MAX_NUMBER_OF_DEVICEN_COLOR_COMPONENTS = 8;
114114

115+
private static final Logger logger = LoggerFactory.getLogger(PdfAChecker.class);
116+
115117
/**
116118
* Creates a PdfA1Checker with the required conformance level
117119
*
@@ -429,7 +431,6 @@ protected void checkLogicalStructure(PdfDictionary catalog) {
429431
throw new PdfAConformanceException(PdfAConformanceException.A_CATALOG_SHALL_INCLUDE_MARK_INFO_DICTIONARY_WITH_MARKED_TRUE_VALUE);
430432
}
431433
if (!catalog.containsKey(PdfName.Lang)) {
432-
Logger logger = LoggerFactory.getLogger(PdfAChecker.class);
433434
logger.warn(PdfAConformanceLogMessageConstant.CATALOG_SHOULD_CONTAIN_LANG_ENTRY);
434435
}
435436
}
@@ -637,7 +638,8 @@ protected void checkAnnotation(PdfDictionary annotDic) {
637638

638639
if (checkStructure(conformanceLevel)) {
639640
if (contentAnnotations.contains(subtype) && !annotDic.containsKey(PdfName.Contents)) {
640-
throw new PdfAConformanceException(PdfAConformanceException.ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY).setMessageParams(subtype.getValue());
641+
logger.warn(MessageFormatUtil.format(
642+
PdfAConformanceLogMessageConstant.ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY, subtype.getValue()));
641643
}
642644
}
643645
}

pdfa/src/main/java/com/itextpdf/pdfa/checker/PdfA2Checker.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.pdfa.checker;
2424

25+
import com.itextpdf.commons.utils.MessageFormatUtil;
2526
import com.itextpdf.forms.fields.PdfFormField;
2627
import com.itextpdf.io.colors.IccProfile;
2728
import com.itextpdf.io.font.FontEncoding;
@@ -158,6 +159,8 @@ public class PdfA2Checker extends PdfA1Checker {
158159
static final int MIN_PAGE_SIZE = 3;
159160
private static final int MAX_NUMBER_OF_DEVICEN_COLOR_COMPONENTS = 32;
160161

162+
private static final Logger logger = LoggerFactory.getLogger(PdfAChecker.class);
163+
161164
private boolean currentFillCsIsIccBasedCMYK = false;
162165
private boolean currentStrokeCsIsIccBasedCMYK = false;
163166

@@ -455,7 +458,8 @@ protected void checkAnnotation(PdfDictionary annotDic) {
455458

456459
if (checkStructure(conformanceLevel)) {
457460
if (contentAnnotations.contains(subtype) && !annotDic.containsKey(PdfName.Contents)) {
458-
throw new PdfAConformanceException(PdfAConformanceException.ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY).setMessageParams(subtype.getValue());
461+
logger.warn(MessageFormatUtil.format(
462+
PdfAConformanceLogMessageConstant.ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY, subtype.getValue()));
459463
}
460464
}
461465

@@ -645,7 +649,6 @@ protected void checkFileSpec(PdfDictionary fileSpec) {
645649
throw new PdfAConformanceException(PdfAConformanceException.FILE_SPECIFICATION_DICTIONARY_SHALL_CONTAIN_F_KEY_AND_UF_KEY);
646650
}
647651
if (!fileSpec.containsKey(PdfName.Desc)) {
648-
Logger logger = LoggerFactory.getLogger(PdfAChecker.class);
649652
logger.warn(PdfAConformanceLogMessageConstant.FILE_SPECIFICATION_DICTIONARY_SHOULD_CONTAIN_DESC_KEY);
650653
}
651654

@@ -655,7 +658,6 @@ protected void checkFileSpec(PdfDictionary fileSpec) {
655658
throw new PdfAConformanceException(PdfAConformanceException.EF_KEY_OF_FILE_SPECIFICATION_DICTIONARY_SHALL_CONTAIN_DICTIONARY_WITH_VALID_F_KEY);
656659
}
657660
// iText doesn't check whether provided file is compliant to PDF-A specs.
658-
Logger logger = LoggerFactory.getLogger(PdfAChecker.class);
659661
logger.warn(PdfAConformanceLogMessageConstant.EMBEDDED_FILE_SHALL_BE_COMPLIANT_WITH_SPEC);
660662
}
661663
}
@@ -1050,7 +1052,6 @@ private void checkBlendMode(PdfName blendMode) {
10501052
private void checkSeparationInsideDeviceN(PdfArray separation, PdfObject deviceNColorSpace, PdfObject deviceNTintTransform) {
10511053
if (!isAltCSIsTheSame(separation.get(2), deviceNColorSpace) ||
10521054
!deviceNTintTransform.equals(separation.get(3))) {
1053-
Logger logger = LoggerFactory.getLogger(PdfAChecker.class);
10541055
logger.warn(PdfAConformanceLogMessageConstant.TINT_TRANSFORM_AND_ALTERNATE_SPACE_OF_SEPARATION_ARRAYS_IN_THE_COLORANTS_OF_DEVICE_N_SHOULD_BE_CONSISTENT_WITH_SAME_ATTRIBUTES_OF_DEVICE_N);
10551056
}
10561057
checkSeparationCS(separation);

pdfa/src/main/java/com/itextpdf/pdfa/exceptions/PdfAConformanceException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public class PdfAConformanceException extends PdfException {
5656
public static final String AN_EXTGSTATE_DICTIONARY_SHALL_NOT_CONTAIN_THE_TR_KEY = "An extgstate dictionary shall not contain the tr key";
5757
public static final String AN_IMAGE_DICTIONARY_SHALL_NOT_CONTAIN_ALTERNATES_KEY = "An image dictionary shall not contain alternates key";
5858
public static final String AN_IMAGE_DICTIONARY_SHALL_NOT_CONTAIN_OPI_KEY = "An image dictionary shall not contain opi key";
59+
@Deprecated
60+
// Was moved to PdfAConformanceLogMessageConstant
5961
public static final String ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY = "Annotation of type {0} should have contents key";
6062
public static final String ANNOTATION_TYPE_0_IS_NOT_PERMITTED = "Annotation type {0} is not permitted";
6163
public static final String APPEARANCE_DICTIONARY_OF_WIDGET_SUBTYPE_AND_BTN_FIELD_TYPE_SHALL_CONTAIN_ONLY_THE_N_KEY_WITH_DICTIONARY_VALUE = "Appearance dictionary of widget subtype and btn field type shall contain only the n key with dictionary value";

pdfa/src/main/java/com/itextpdf/pdfa/logs/PdfAConformanceLogMessageConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This file is part of the iText (R) project.
2626
* Class containing pdfa conformance constants to be used in logging.
2727
*/
2828
public final class PdfAConformanceLogMessageConstant {
29+
public static final String ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY = "Annotation of type {0} should have contents key";
2930
public static final String CATALOG_SHOULD_CONTAIN_LANG_ENTRY =
3031
"Catalog dictionary should contain lang entry";
3132

pdfa/src/test/java/com/itextpdf/pdfa/PdfA1AnnotationCheckTest.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.pdfa;
2424

25-
import com.itextpdf.io.source.ByteArrayOutputStream;
2625
import com.itextpdf.commons.utils.MessageFormatUtil;
26+
import com.itextpdf.io.source.ByteArrayOutputStream;
2727
import com.itextpdf.kernel.geom.Rectangle;
2828
import com.itextpdf.kernel.pdf.PdfAConformanceLevel;
2929
import com.itextpdf.kernel.pdf.PdfDictionary;
@@ -42,20 +42,23 @@ This file is part of the iText (R) project.
4242
import com.itextpdf.kernel.pdf.annot.PdfWidgetAnnotation;
4343
import com.itextpdf.kernel.utils.CompareTool;
4444
import com.itextpdf.pdfa.exceptions.PdfAConformanceException;
45+
import com.itextpdf.pdfa.logs.PdfAConformanceLogMessageConstant;
4546
import com.itextpdf.test.ExtendedITextTest;
47+
import com.itextpdf.test.LogLevelConstants;
48+
import com.itextpdf.test.annotations.LogMessage;
49+
import com.itextpdf.test.annotations.LogMessages;
4650
import com.itextpdf.test.annotations.type.IntegrationTest;
47-
48-
import org.junit.Assert;
49-
import org.junit.BeforeClass;
50-
import org.junit.Test;
51-
import org.junit.experimental.categories.Category;
51+
import com.itextpdf.test.pdfa.VeraPdfValidator;
5252

5353
import java.io.FileInputStream;
5454
import java.io.FileNotFoundException;
5555
import java.io.IOException;
5656
import java.io.InputStream;
5757
import java.nio.charset.StandardCharsets;
58-
58+
import org.junit.Assert;
59+
import org.junit.BeforeClass;
60+
import org.junit.Test;
61+
import org.junit.experimental.categories.Category;
5962
import static org.junit.Assert.fail;
6063

6164
@Category(IntegrationTest.class)
@@ -204,8 +207,14 @@ public void annotationCheckTest07() throws IOException, InterruptedException {
204207
}
205208

206209
@Test
207-
public void annotationCheckTest08() throws FileNotFoundException {
208-
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
210+
@LogMessages(messages = {
211+
@LogMessage(messageTemplate = PdfAConformanceLogMessageConstant.ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY, logLevel = LogLevelConstants.WARN)
212+
})
213+
public void annotationCheckTest08() throws IOException, InterruptedException {
214+
String outPdf = destinationFolder + "pdfA1a_annotationCheckTest08.pdf";
215+
String cmpPdf = cmpFolder + "cmp_pdfA1a_annotationCheckTest08.pdf";
216+
217+
PdfWriter writer = new PdfWriter(outPdf);
209218
InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm");
210219
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", is));
211220
doc.setTagged();
@@ -218,9 +227,9 @@ public void annotationCheckTest08() throws FileNotFoundException {
218227

219228
page.addAnnotation(annot);
220229

221-
Exception e = Assert.assertThrows(PdfAConformanceException.class, () -> doc.close());
222-
Assert.assertEquals(MessageFormatUtil.format(PdfAConformanceException.ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY,
223-
PdfName.Stamp.getValue()), e.getMessage());
230+
doc.close();
231+
compareResult(outPdf, cmpPdf);
232+
Assert.assertNull(new VeraPdfValidator().validate(outPdf)); // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
224233
}
225234

226235
@Test

pdfa/src/test/java/com/itextpdf/pdfa/PdfA2AnnotationCheckTest.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ This file is part of the iText (R) project.
2323
package com.itextpdf.pdfa;
2424

2525
import com.itextpdf.io.source.ByteArrayOutputStream;
26-
import com.itextpdf.commons.utils.MessageFormatUtil;
2726
import com.itextpdf.kernel.font.PdfFont;
2827
import com.itextpdf.kernel.font.PdfFontFactory;
2928
import com.itextpdf.kernel.font.PdfFontFactory.EmbeddingStrategy;
@@ -46,19 +45,22 @@ This file is part of the iText (R) project.
4645
import com.itextpdf.kernel.pdf.xobject.PdfFormXObject;
4746
import com.itextpdf.kernel.utils.CompareTool;
4847
import com.itextpdf.pdfa.exceptions.PdfAConformanceException;
48+
import com.itextpdf.pdfa.logs.PdfAConformanceLogMessageConstant;
4949
import com.itextpdf.test.ExtendedITextTest;
50+
import com.itextpdf.test.LogLevelConstants;
51+
import com.itextpdf.test.annotations.LogMessage;
52+
import com.itextpdf.test.annotations.LogMessages;
5053
import com.itextpdf.test.annotations.type.IntegrationTest;
51-
52-
import org.junit.Assert;
53-
import org.junit.BeforeClass;
54-
import org.junit.Test;
55-
import org.junit.experimental.categories.Category;
54+
import com.itextpdf.test.pdfa.VeraPdfValidator;
5655

5756
import java.io.FileInputStream;
5857
import java.io.FileNotFoundException;
5958
import java.io.IOException;
6059
import java.io.InputStream;
61-
60+
import org.junit.Assert;
61+
import org.junit.BeforeClass;
62+
import org.junit.Test;
63+
import org.junit.experimental.categories.Category;
6264
import static org.junit.Assert.fail;
6365

6466
@Category(IntegrationTest.class)
@@ -290,8 +292,14 @@ public void annotationCheckTest11() throws IOException, InterruptedException {
290292
}
291293

292294
@Test
293-
public void annotationCheckTest12() throws FileNotFoundException {
294-
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
295+
@LogMessages(messages = {
296+
@LogMessage(messageTemplate = PdfAConformanceLogMessageConstant.ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY, logLevel = LogLevelConstants.WARN)
297+
})
298+
public void annotationCheckTest12() throws IOException, InterruptedException {
299+
String outPdf = destinationFolder + "pdfA1a_annotationCheckTest12.pdf";
300+
String cmpPdf = cmpFolder + "cmp_pdfA1a_annotationCheckTest12.pdf";
301+
302+
PdfWriter writer = new PdfWriter(outPdf);
295303
InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm");
296304
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2A, new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", is));
297305
doc.setTagged();
@@ -301,12 +309,13 @@ public void annotationCheckTest12() throws FileNotFoundException {
301309
Rectangle rect = new Rectangle(100, 650, 400, 100);
302310
PdfAnnotation annot = new PdfStampAnnotation(rect);
303311
annot.setFlags(PdfAnnotation.PRINT);
312+
annot.setNormalAppearance(createAppearance(doc, new Rectangle(400, 100)));
304313

305314
page.addAnnotation(annot);
306315

307-
Exception e = Assert.assertThrows(PdfAConformanceException.class, () -> doc.close());
308-
Assert.assertEquals(MessageFormatUtil.format(PdfAConformanceException.ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY, PdfName.Stamp.getValue()),
309-
e.getMessage());
316+
doc.close();
317+
compareResult(outPdf, cmpPdf);
318+
Assert.assertNull(new VeraPdfValidator().validate(outPdf)); // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
310319
}
311320

312321
@Test

0 commit comments

Comments
 (0)