PdfA2Checker extends PdfA1Checker { @Override protected void checkCatalogValidEntries(PdfDictionary catalogDict) { if (catalogDict.containsKey(PdfName.NeedsRendering)) { throw new PdfAConformanceException(PdfAConformanceException.THE_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_THE_NEEDSRENDERING_KEY); } if (catalogDict.containsKey(PdfName.AA)) { throw new PdfAConformanceException(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_AA_ENTRY); } if (catalogDict.containsKey(PdfName.Requirements)) { throw new PdfAConformanceException(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_REQUIREMENTS_ENTRY); } PdfDictionary permissions = catalogDict.getAsDictionary(PdfName.Perms); if (permissions != null) { for (PdfName dictKey : permissions.keySet()) { if (PdfName.DocMDP.equals(dictKey)) { PdfDictionary signatureDict = permissions.getAsDictionary(PdfName.DocMDP); if (signatureDict != null) { PdfArray references = signatureDict.getAsArray(PdfName.Reference); if (references != null) { for (int i = 0; i < references.size(); i++) { PdfDictionary referenceDict = references.getAsDictionary(i); if (referenceDict.containsKey(PdfName.DigestLocation) || referenceDict.containsKey(PdfName.DigestMethod) || referenceDict.containsKey(PdfName.DigestValue)) { throw new PdfAConformanceException(PdfAConformanceException.SIGNATURE_REFERENCES_DICTIONARY_SHALL_NOT_CONTAIN_DIGESTLOCATION_DIGESTMETHOD_DIGESTVALUE); } } } } } else if (PdfName.UR3.equals(dictKey)) { } else { throw new PdfAConformanceException(PdfAConformanceException.NO_KEYS_OTHER_THAN_UR3_AND_DOC_MDP_SHALL_BE_PRESENT_IN_A_PERMISSIONS_DICTIONARY); } } } PdfDictionary namesDictionary = catalogDict.getAsDictionary(PdfName.Names); if (namesDictionary != null && namesDictionary.containsKey(PdfName.AlternatePresentations)) { throw new PdfAConformanceException(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_ALTERNATEPRESENTATIONS_NAMES_ENTRY); } PdfDictionary oCProperties = catalogDict.getAsDictionary(PdfName.OCProperties); if (oCProperties != null) { List<PdfDictionary> configList = new ArrayList<>(); PdfDictionary d = oCProperties.getAsDictionary(PdfName.D); if (d != null) { configList.add(d); } PdfArray configs = oCProperties.getAsArray(PdfName.Configs); if (configs != null) { for (PdfObject config : configs) { configList.add((PdfDictionary) config); } } HashSet<PdfObject> ocgs = new HashSet<>(); PdfArray ocgsArray = oCProperties.getAsArray(PdfName.OCGs); if (ocgsArray != null) { for (PdfObject ocg : ocgsArray) { ocgs.add(ocg); } } HashSet<String> names = new HashSet<>(); for (PdfDictionary config : configList) { checkCatalogConfig(config, ocgs, names); } } } PdfA2Checker(PdfAConformanceLevel conformanceLevel); @Override void checkInlineImage(PdfStream inlineImage, PdfDictionary currentColorSpaces); @Override void checkColor(Color color, PdfDictionary currentColorSpaces, Boolean fill); @Override void checkColor(Color color, PdfDictionary currentColorSpaces, Boolean fill, PdfStream contentStream); @Override void checkColorSpace(PdfColorSpace colorSpace, PdfDictionary currentColorSpaces, boolean checkAlternate, Boolean fill); @Override void checkExtGState(CanvasGraphicsState extGState); @Override void checkExtGState(CanvasGraphicsState extGState, PdfStream contentStream); @Override void checkFontGlyphs(PdfFont font, PdfStream contentStream);  }
@Test public void checkNameEntryShouldBeUniqueBetweenDefaultAndAdditionalConfigs() { junitExpectedException.expect(PdfAConformanceException.class); junitExpectedException.expectMessage(PdfAConformanceException.VALUE_OF_NAME_ENTRY_SHALL_BE_UNIQUE_AMONG_ALL_OPTIONAL_CONTENT_CONFIGURATION_DICTIONARIES); PdfDictionary ocProperties = new PdfDictionary(); PdfDictionary d = new PdfDictionary(); d.put(PdfName.Name, new PdfString("CustomName")); PdfArray configs = new PdfArray(); PdfDictionary config = new PdfDictionary(); config.put(PdfName.Name, new PdfString("CustomName")); configs.add(config); ocProperties.put(PdfName.D, d); ocProperties.put(PdfName.Configs, configs); PdfDictionary catalog = new PdfDictionary(); catalog.put(PdfName.OCProperties, ocProperties); pdfA2Checker.checkCatalogValidEntries(catalog); }
@Test public void checkNameEntryShouldBeUniqueBetweenAdditionalConfigs() { junitExpectedException.expect(PdfAConformanceException.class); junitExpectedException.expectMessage(PdfAConformanceException.VALUE_OF_NAME_ENTRY_SHALL_BE_UNIQUE_AMONG_ALL_OPTIONAL_CONTENT_CONFIGURATION_DICTIONARIES); PdfDictionary ocProperties = new PdfDictionary(); PdfDictionary d = new PdfDictionary(); d.put(PdfName.Name, new PdfString("CustomName")); PdfArray configs = new PdfArray(); PdfDictionary config = new PdfDictionary(); config.put(PdfName.Name, new PdfString("CustomName1")); configs.add(config); config = new PdfDictionary(); config.put(PdfName.Name, new PdfString("CustomName1")); configs.add(config); ocProperties.put(PdfName.D, d); ocProperties.put(PdfName.Configs, configs); PdfDictionary catalog = new PdfDictionary(); catalog.put(PdfName.OCProperties, ocProperties); pdfA2Checker.checkCatalogValidEntries(catalog); }
@Test public void checkOCCDContainName() { junitExpectedException.expect(PdfAConformanceException.class); junitExpectedException.expectMessage(PdfAConformanceException.OPTIONAL_CONTENT_CONFIGURATION_DICTIONARY_SHALL_CONTAIN_NAME_ENTRY); PdfDictionary ocProperties = new PdfDictionary(); PdfDictionary d = new PdfDictionary(); PdfArray configs = new PdfArray(); PdfDictionary config = new PdfDictionary(); config.put(PdfName.Name, new PdfString("CustomName1")); configs.add(config); config = new PdfDictionary(); config.put(PdfName.Name, new PdfString("CustomName2")); configs.add(config); ocProperties.put(PdfName.D, d); ocProperties.put(PdfName.Configs, configs); PdfDictionary catalog = new PdfDictionary(); catalog.put(PdfName.OCProperties, ocProperties); pdfA2Checker.checkCatalogValidEntries(catalog); }
@Test public void checkOrderArrayDoesNotContainRedundantReferences() { junitExpectedException.expect(PdfAConformanceException.class); junitExpectedException.expectMessage(PdfAConformanceException.ORDER_ARRAY_SHALL_CONTAIN_REFERENCES_TO_ALL_OCGS); PdfDictionary ocProperties = new PdfDictionary(); PdfDictionary d = new PdfDictionary(); d.put(PdfName.Name, new PdfString("CustomName")); PdfArray configs = new PdfArray(); PdfDictionary config = new PdfDictionary(); config.put(PdfName.Name, new PdfString("CustomName1")); PdfArray order = new PdfArray(); PdfDictionary orderItem = new PdfDictionary(); orderItem.put(PdfName.Name, new PdfString("CustomName2")); order.add(orderItem); PdfDictionary orderItem1 = new PdfDictionary(); orderItem1.put(PdfName.Name, new PdfString("CustomName3")); order.add(orderItem1); config.put(PdfName.Order, order); PdfArray ocgs = new PdfArray(); ocgs.add(orderItem); ocProperties.put(PdfName.OCGs, ocgs); configs.add(config); ocProperties.put(PdfName.D, d); ocProperties.put(PdfName.Configs, configs); PdfDictionary catalog = new PdfDictionary(); catalog.put(PdfName.OCProperties, ocProperties); pdfA2Checker.checkCatalogValidEntries(catalog); }
@Test public void checkOrderArrayContainsReferencesToAllOCGs() { junitExpectedException.expect(PdfAConformanceException.class); junitExpectedException.expectMessage(PdfAConformanceException.ORDER_ARRAY_SHALL_CONTAIN_REFERENCES_TO_ALL_OCGS); PdfDictionary ocProperties = new PdfDictionary(); PdfDictionary d = new PdfDictionary(); d.put(PdfName.Name, new PdfString("CustomName")); PdfArray configs = new PdfArray(); PdfDictionary config = new PdfDictionary(); config.put(PdfName.Name, new PdfString("CustomName1")); PdfArray order = new PdfArray(); PdfDictionary orderItem = new PdfDictionary(); orderItem.put(PdfName.Name, new PdfString("CustomName2")); order.add(orderItem); PdfDictionary orderItem1 = new PdfDictionary(); orderItem1.put(PdfName.Name, new PdfString("CustomName3")); config.put(PdfName.Order, order); PdfArray ocgs = new PdfArray(); ocgs.add(orderItem); ocgs.add(orderItem1); ocProperties.put(PdfName.OCGs, ocgs); configs.add(config); ocProperties.put(PdfName.D, d); ocProperties.put(PdfName.Configs, configs); PdfDictionary catalog = new PdfDictionary(); catalog.put(PdfName.OCProperties, ocProperties); pdfA2Checker.checkCatalogValidEntries(catalog); }
@Test public void checkOrderArrayAndOCGsMatch() { junitExpectedException.expect(PdfAConformanceException.class); junitExpectedException.expectMessage(PdfAConformanceException.ORDER_ARRAY_SHALL_CONTAIN_REFERENCES_TO_ALL_OCGS); PdfDictionary ocProperties = new PdfDictionary(); PdfDictionary d = new PdfDictionary(); d.put(PdfName.Name, new PdfString("CustomName")); PdfArray configs = new PdfArray(); PdfDictionary config = new PdfDictionary(); config.put(PdfName.Name, new PdfString("CustomName1")); PdfArray order = new PdfArray(); PdfDictionary orderItem = new PdfDictionary(); orderItem.put(PdfName.Name, new PdfString("CustomName2")); order.add(orderItem); PdfDictionary orderItem1 = new PdfDictionary(); orderItem1.put(PdfName.Name, new PdfString("CustomName3")); order.add(orderItem1); config.put(PdfName.Order, order); PdfArray ocgs = new PdfArray(); PdfDictionary orderItem2 = new PdfDictionary(); orderItem2.put(PdfName.Name, new PdfString("CustomName4")); ocgs.add(orderItem2); PdfDictionary orderItem3 = new PdfDictionary(); orderItem3.put(PdfName.Name, new PdfString("CustomName5")); ocgs.add(orderItem3); ocProperties.put(PdfName.OCGs, ocgs); configs.add(config); ocProperties.put(PdfName.D, d); ocProperties.put(PdfName.Configs, configs); PdfDictionary catalog = new PdfDictionary(); catalog.put(PdfName.OCProperties, ocProperties); pdfA2Checker.checkCatalogValidEntries(catalog); }
@Test public void checkAbsenceOfOptionalConfigEntryAllowed() { PdfDictionary ocProperties = new PdfDictionary(); PdfDictionary d = new PdfDictionary(); d.put(PdfName.Name, new PdfString("CustomName")); PdfDictionary orderItem = new PdfDictionary(); orderItem.put(PdfName.Name, new PdfString("CustomName2")); PdfArray ocgs = new PdfArray(); ocgs.add(orderItem); ocProperties.put(PdfName.OCGs, ocgs); ocProperties.put(PdfName.D, d); PdfDictionary catalog = new PdfDictionary(); catalog.put(PdfName.OCProperties, ocProperties); pdfA2Checker.checkCatalogValidEntries(catalog); }
@Test public void checkAbsenceOfOptionalOrderEntryAllowed() { PdfDictionary ocProperties = new PdfDictionary(); PdfDictionary d = new PdfDictionary(); d.put(PdfName.Name, new PdfString("CustomName")); PdfDictionary orderItem = new PdfDictionary(); orderItem.put(PdfName.Name, new PdfString("CustomName2")); PdfArray ocgs = new PdfArray(); ocgs.add(orderItem); PdfArray configs = new PdfArray(); PdfDictionary config = new PdfDictionary(); config.put(PdfName.Name, new PdfString("CustomName1")); configs.add(config); ocProperties.put(PdfName.OCGs, ocgs); ocProperties.put(PdfName.D, d); ocProperties.put(PdfName.Configs, configs); PdfDictionary catalog = new PdfDictionary(); catalog.put(PdfName.OCProperties, ocProperties); pdfA2Checker.checkCatalogValidEntries(catalog); }
@Test public void checkCatalogDictionaryWithoutAlternatePresentations() { junitExpectedException.expect(PdfAConformanceException.class); junitExpectedException.expectMessage(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_ALTERNATEPRESENTATIONS_NAMES_ENTRY); PdfDictionary names = new PdfDictionary(); names.put(PdfName.AlternatePresentations, new PdfDictionary()); PdfDictionary catalog = new PdfDictionary(); catalog.put(PdfName.Names, names); pdfA2Checker.checkCatalogValidEntries(catalog); }
@Test public void checkCatalogDictionaryWithoutRequirements() { junitExpectedException.expect(PdfAConformanceException.class); junitExpectedException.expectMessage(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_REQUIREMENTS_ENTRY); PdfDictionary catalog = new PdfDictionary(); catalog.put(PdfName.Requirements, new PdfDictionary()); pdfA2Checker.checkCatalogValidEntries(catalog); }