/** * 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 { ICCProfileWrapper iccpw = ICCProfileWrapper.getOrSearchICCProfile(ctx); if (iccpw != null) { return iccpw.isRGBColorSpace(); } return false; }
/** * Return an instance of ColorSpaceHelper according to the ColorSpaceRestiction value. * <UL> * <li>ColorSpaceRestiction.NO_PATTERN : returns NoPatternColorSpaceHelper * <li>ColorSpaceRestiction.ONLY_DEVICE : returns DeviceColorSpaceHelper * <li>default : returns StandardColorSpaceHelper * </UL> * * @param context * the PreflightContext to access useful data * @param cs * the High level PDFBox object which represents the ColorSpace * @param csr * the color space restriction * @return the ColorSpaceHelper instance. */ public ColorSpaceHelper getColorSpaceHelper(PreflightContext context, PDColorSpace cs, ColorSpaceRestriction csr) { switch (csr) { case NO_PATTERN: return new NoPatternColorSpaceHelper(context, cs); case ONLY_DEVICE: return new DeviceColorSpaceHelper(context, cs); default: return new StandardColorSpaceHelper(context, cs); } }
@Override public final void validate() throws ValidationException { if (pdcs == null) { throw new ValidationException("Unable to create a PDColorSpace with the value null"); } this.iccpw = ICCProfileWrapper.getOrSearchICCProfile(context); processAllColorSpace(pdcs); }
ColorSpaces cs = ColorSpaces.valueOf(colorSpace.getName()); processRGBColorSpace(colorSpace); break; case DeviceCMYK: case CMYK: processCYMKColorSpace(colorSpace); break; case CalRGB: case CalGray: case Lab: processCalibratedColorSpace(colorSpace); break; case DeviceGray: case G: processGrayColorSpace(colorSpace); break; case ICCBased: processICCBasedColorSpace(colorSpace); break; case DeviceN: processDeviceNColorSpace(colorSpace); break; case Indexed: case I: processIndexedColorSpace(colorSpace); break; case Separation: processSeparationColorSpace(colorSpace);
private boolean validColorSpaceDestOutputProfile(ColorSpaceType expectedType) throws ContentStreamException { try { ICCProfileWrapper profileWrapper = ICCProfileWrapper.getOrSearchICCProfile(context); if (profileWrapper == null) { return false; } switch (expectedType) { case RGB: return profileWrapper.isRGBColorSpace(); case CMYK: return profileWrapper.isCMYKColorSpace(); default: return true; } } catch (ValidationException e) { throw new ContentStreamException(e); } }
ColorSpaceHelper csHelper = colorSpaceFactory.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION); csHelper.validate();
/** * Indexed color space is authorized only if the BaseColorSpace is a DeviceXXX color space. In all other cases the * given list is updated with a ValidationError (ERROR_GRAPHIC_INVALID_PATTERN_COLOR_SPACE_FORBIDDEN) and returns * false. */ @Override protected void processIndexedColorSpace(PDColorSpace colorSpace) { PDIndexed indexed = (PDIndexed) colorSpace; PDColorSpace baseColorSpace = indexed.getBaseColorSpace(); ColorSpaces colorSpaces = ColorSpaces.valueOf(baseColorSpace.getName()); switch (colorSpaces) { case Indexed: case I: case Pattern: context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_FORBIDDEN, colorSpaces .getLabel() + " ColorSpace is forbidden")); break; default: processAllColorSpace(baseColorSpace); } } }
if (altCol != null) ColorSpaces acs = ColorSpaces.valueOf(altCol.getName()); switch (acs) case I: context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_ALTERNATE, acs .getLabel() + " color space can't be used as alternate color space")); break; default: processAllColorSpace(altCol);
try cs = ColorSpaces.valueOf(colorSpaceName); if (pdCS != null) cs = ColorSpaces.valueOf(pdCS.getName()); PreflightConfiguration cfg = context.getConfig(); ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact(); csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION); PreflightConfiguration cfg = context.getConfig(); ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact(); csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION); csHelper.validate();
/** * Method called by the processAllColorSpace if the ColorSpace to check is DeviceCYMK. * */ protected void processCYMKColorSpace(PDColorSpace colorSpace) { if (!processDefaultColorSpace(colorSpace)) { if (iccpw == null) { context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_MISSING, "DestOutputProfile is missing")); } else if (!iccpw.isCMYKColorSpace()) { context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_CMYK, "DestOutputProfile isn't CMYK ColorSpace")); } } }
/** * Method called by the processAllColorSpace if the ColorSpace to check is DeviceRGB. * */ protected void processRGBColorSpace(PDColorSpace colorSpace) { if (!processDefaultColorSpace(colorSpace)) { if (iccpw == null) { context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_MISSING, "DestOutputProfile is missing")); } else if (!iccpw.isRGBColorSpace()) { context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_RGB, "DestOutputProfile isn't RGB ColorSpace")); } } }
/** * Method called by the processAllColorSpace if the ColorSpace to check is Indexed. Because this kind of ColorSpace * can have a Base color space, the processAllColorSpace is called to check this base color space. (Indexed and * Pattern can't be a Base color space) * * @param colorSpace * the color space object to check. */ protected void processIndexedColorSpace(PDColorSpace colorSpace) { PDIndexed indexed = (PDIndexed) colorSpace; PDColorSpace based = indexed.getBaseColorSpace(); ColorSpaces cs = ColorSpaces.valueOf(based.getName()); if (cs == ColorSpaces.Indexed || cs == ColorSpaces.I) { context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_INDEXED, "Indexed color space can't be used as Base color space")); return; } if (cs == ColorSpaces.Pattern) { context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_INDEXED, "Pattern color space can't be used as Base color space")); return; } processAllColorSpace(based); }
if (colorSpace.getName().equals(ColorSpaces.DeviceCMYK.getLabel()) && resources.hasColorSpace(COSName.DEFAULT_CMYK)) else if (colorSpace.getName().equals(ColorSpaces.DeviceRGB.getLabel()) && resources.hasColorSpace(COSName.DEFAULT_RGB)) else if (colorSpace.getName().equals(ColorSpaces.DeviceGray.getLabel()) && resources.hasColorSpace(COSName.DEFAULT_GRAY)) processAllColorSpace(defaultCS); int newNbOfErrors = context.getDocument().getResult().getErrorsList().size(); result = (nbOfErrors == newNbOfErrors);
private ColorSpaceHelper getColorSpaceHelper(PDColorSpace pdCS) { PreflightConfiguration cfg = context.getConfig(); ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact(); return csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.ONLY_DEVICE); }
/** * Method called by the processAllColorSpace if the ColorSpace to check is DeviceGray. * */ protected void processGrayColorSpace(PDColorSpace colorSpace) { if (!processDefaultColorSpace(colorSpace) && iccpw == null) { context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_MISSING, "DestOutputProfile is missing")); } }
public static ICCProfileWrapper getOrSearchICCProfile(PreflightContext context) throws ValidationException { ICCProfileWrapper profileWrapper = context.getIccProfileWrapper(); if (profileWrapper == null && !context.isIccProfileAlreadySearched()) { profileWrapper = searchFirstICCProfile(context); context.setIccProfileAlreadySearched(true); } return profileWrapper; } }
public static PreflightConfiguration createPdfA1BConfiguration() { PreflightConfiguration configuration = new PreflightConfiguration(); configuration.replaceProcess(CATALOG_PROCESS, CatalogValidationProcess.class); configuration.replaceProcess(FILE_SPECIF_PROCESS, FileSpecificationValidationProcess.class); configuration.replaceProcess(TRAILER_PROCESS, TrailerValidationProcess.class); configuration.replaceProcess(XREF_PROCESS, XRefValidationProcess.class); configuration.replaceProcess(ACRO_FORM_PROCESS, AcroFormValidationProcess.class); configuration.replaceProcess(BOOKMARK_PROCESS, BookmarkValidationProcess.class); configuration.replaceProcess(PAGES_TREE_PROCESS, PageTreeValidationProcess.class); configuration.replaceProcess(META_DATA_PROCESS, MetadataValidationProcess.class); configuration.replaceProcess(STREAM_PROCESS, StreamValidationProcess.class); configuration.replacePageProcess(PAGE_PROCESS, SinglePageValidationProcess.class); configuration.replacePageProcess(EXTGSTATE_PROCESS, ExtGStateValidationProcess.class); configuration.replacePageProcess(SHADING_PATTERN_PROCESS, ShadingPatternValidationProcess.class); configuration.replacePageProcess(GRAPHIC_PROCESS, GraphicObjectPageValidationProcess.class); configuration.replacePageProcess(TILING_PATTERN_PROCESS, TilingPatternValidationProcess.class); configuration.replacePageProcess(RESOURCES_PROCESS, ResourcesValidationProcess.class); configuration.replacePageProcess(FONT_PROCESS, FontValidationProcess.class); configuration.replacePageProcess(ACTIONS_PROCESS, ActionsValidationProcess.class); configuration.replacePageProcess(ANNOTATIONS_PROCESS, AnnotationValidationProcess.class); configuration.replacePageProcess(DESTINATION_PROCESS, DestinationValidationProcess.class); configuration.actionFact = new ActionManagerFactory(); configuration.annotFact = new PDFAbAnnotationFactory(); configuration.colorSpaceHelperFact = new ColorSpaceHelperFactory(); return configuration; }
/** * Checks if the ColorSapce entry is consistent which rules of the PDF Reference and the ISO 190005-1:2005 * Specification. * * This method is called by the validate method. * * @param context the preflight context. * @param page the page to check. * @param shadingRes the Shading pattern to check. * @throws ValidationException */ protected void checkColorSpace(PreflightContext context, PDPage page, PDShading shadingRes) throws ValidationException { try { PDColorSpace pColorSpace = shadingRes.getColorSpace(); PreflightConfiguration config = context.getConfig(); ColorSpaceHelperFactory csFact = config.getColorSpaceHelperFact(); ColorSpaceHelper csh = csFact.getColorSpaceHelper(context, pColorSpace, ColorSpaceRestriction.NO_PATTERN); csh.validate(); } catch (IOException e) { LOGGER.debug("Unable to get the color space", e); context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_UNKNOWN_COLOR_SPACE, e.getMessage())); } }
ColorSpaceHelperFactory csFact = config.getColorSpaceHelperFact(); PDColorSpace pdCS = PDColorSpace.create(csImg); ColorSpaceHelper csh = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_PATTERN); csh.validate();