public class ColorContrastChecker extends Object implements IValidationChecker
This checker validates the contrast ratio between text and background colors to ensure readability for users with visual impairments. It supports both WCAG 2.0 Level AA and Level AAA conformance levels.
Features: @see ContrastAnalyzer for details.
Current Limitations @see ContrastAnalyzer for details.
| Constructor and Description |
|---|
ColorContrastChecker(boolean checkIndividualGlyphs,
boolean throwExceptionOnFailure)
Creates a new ColorContrastChecker with the specified configuration.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
isPdfObjectReadyToFlush(PdfObject object)
Determines if a PDF object is ready to be flushed to the output stream.
|
ColorContrastChecker |
setCheckWcagAA(boolean checkWcagAA)
Sets whether to check for WCAG AA compliance.
|
ColorContrastChecker |
setCheckWcagAAA(boolean checkWcagAAA)
Sets whether to check for WCAG AAA compliance.
|
void |
setMinimalPercentualCoverage(double minimalPercentualCoverage)
Sets the minimal percentual coverage of text area that must be covered by a background
element for its contrast ratio to be considered in the analysis.
|
void |
validate(IValidationContext validationContext)
Validates the given context for color contrast compliance.
|
public ColorContrastChecker(boolean checkIndividualGlyphs,
boolean throwExceptionOnFailure)
checkIndividualGlyphs - if true, contrast is checked at the individual glyph level;
if false, contrast is checked at the text block level.
Individual glyph checking is more precise but may impact performance.throwExceptionOnFailure - if true, a PdfException is thrown when contrast
requirements are not met; if false, warnings are logged instead.public final void setMinimalPercentualCoverage(double minimalPercentualCoverage)
For example, if set to 0.1 (10%), only background elements that cover at least 10% of the text area will be included in the contrast analysis. This helps filter out insignificant backgrounds that do not meaningfully affect text readability. Like underlines or small decorative elements.
minimalPercentualCoverage - the minimal percentual coverage (between 0.0 and 1.0)public final ColorContrastChecker setCheckWcagAA(boolean checkWcagAA)
checkWcagAA - true to enable WCAG AA compliance checking, false to disablepublic final ColorContrastChecker setCheckWcagAAA(boolean checkWcagAAA)
checkWcagAAA - true to enable WCAG AAA compliance checking, false to disablepublic void validate(IValidationContext validationContext)
This method is called by the validation framework to check color contrast
when a PDF page is being validated. It only processes validation contexts
of type ValidationType.PDF_PAGE.
validate in interface IValidationCheckervalidationContext - the validation context containing the PDF page to validatepublic boolean isPdfObjectReadyToFlush(PdfObject object)
This implementation always returns true as color contrast checking does not impose any restrictions on when objects can be flushed.
isPdfObjectReadyToFlush in interface IValidationCheckerobject - the PDF object to checktrueCopyright © 1998–2026 Apryse Group NV. All rights reserved.