PdfA2Checker extends PdfA1Checker { @Override public void checkColorSpace(PdfColorSpace colorSpace, PdfDictionary currentColorSpaces, boolean checkAlternate, Boolean fill) { if (fill != null) { if ((boolean) fill) { currentFillCsIsIccBasedCMYK = false; } else { currentStrokeCsIsIccBasedCMYK = false; } } if (colorSpace instanceof PdfSpecialCs.Separation) { PdfSpecialCs.Separation separation = (PdfSpecialCs.Separation) colorSpace; checkSeparationCS((PdfArray) separation.getPdfObject()); if (checkAlternate) { checkColorSpace(separation.getBaseCs(), currentColorSpaces, false, fill); } } else if (colorSpace instanceof PdfSpecialCs.DeviceN) { PdfSpecialCs.DeviceN deviceN = (PdfSpecialCs.DeviceN) colorSpace; if (deviceN.getNumberOfComponents() > MAX_NUMBER_OF_DEVICEN_COLOR_COMPONENTS) { throw new PdfAConformanceException(PdfAConformanceException. THE_NUMBER_OF_COLOR_COMPONENTS_IN_DEVICE_N_COLORSPACE_SHOULD_NOT_EXCEED, MAX_NUMBER_OF_DEVICEN_COLOR_COMPONENTS); } PdfDictionary attributes = ((PdfArray) deviceN.getPdfObject()).getAsDictionary(4); PdfDictionary colorants = attributes.getAsDictionary(PdfName.Colorants); if (colorants != null) { for (Map.Entry<PdfName, PdfObject> entry : colorants.entrySet()) { PdfArray separation = (PdfArray) entry.getValue(); checkSeparationInsideDeviceN(separation, ((PdfArray) deviceN.getPdfObject()).get(2), ((PdfArray) deviceN.getPdfObject()).get(3)); } } if (checkAlternate) { checkColorSpace(deviceN.getBaseCs(), currentColorSpaces, false, fill); } } else if (colorSpace instanceof PdfSpecialCs.Indexed) { if (checkAlternate) { checkColorSpace(((PdfSpecialCs.Indexed) colorSpace).getBaseCs(), currentColorSpaces, true, fill); } } else if (colorSpace instanceof PdfSpecialCs.UncoloredTilingPattern) { if (checkAlternate) { checkColorSpace(((PdfSpecialCs.UncoloredTilingPattern) colorSpace).getUnderlyingColorSpace(), currentColorSpaces, true, fill); } } else { if (colorSpace instanceof PdfDeviceCs.Rgb) { if (!checkDefaultCS(currentColorSpaces, fill, PdfName.DefaultRGB, 3)) { rgbIsUsed = true; } } else if (colorSpace instanceof PdfDeviceCs.Cmyk) { if (!checkDefaultCS(currentColorSpaces, fill, PdfName.DefaultCMYK, 4)) { cmykIsUsed = true; } } else if (colorSpace instanceof PdfDeviceCs.Gray) { if (!checkDefaultCS(currentColorSpaces, fill, PdfName.DefaultGray, 1)) { grayIsUsed = true; } } } if (fill != null && colorSpace instanceof PdfCieBasedCs.IccBased) { byte[] iccBytes = ((PdfArray) colorSpace.getPdfObject()).getAsStream(1).getBytes(); if (ICC_COLOR_SPACE_CMYK.equals(IccProfile.getIccColorSpaceName(iccBytes))) { if ((boolean) fill) { currentFillCsIsIccBasedCMYK = true; } else { currentStrokeCsIsIccBasedCMYK = true; } } } } 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 deviceNColorspaceNoAttributesDictionary() { junitExpectedException.expect(RuntimeException.class); int numberOfComponents = 2; List<String> tmpArray = new ArrayList<String>(numberOfComponents); float[] transformArray = new float[numberOfComponents * 2]; for (int i = 0; i < numberOfComponents; i++) { tmpArray.add("MyColor" + i + 1); transformArray[i * 2] = 0; transformArray[i * 2 + 1] = 1; } com.itextpdf.kernel.pdf.function.PdfFunction.Type4 function = new com.itextpdf.kernel.pdf.function.PdfFunction.Type4 (new PdfArray(transformArray), new PdfArray(new float[]{0, 1, 0, 1, 0, 1}), "{0}".getBytes(StandardCharsets.ISO_8859_1)); PdfDictionary currentColorSpaces = new PdfDictionary(); pdfA2Checker.checkColorSpace(new PdfSpecialCs.DeviceN(tmpArray, new PdfDeviceCs.Rgb(), function), currentColorSpaces, true, false); }