public static PDFText extractText(PDPage page, PDAnnotation pdfAnnot, Color textColor) throws IOException { PDFText pdfText = new PDFText("", PDFText.TextType.EMPTY, Color.black, textColor, pdfAnnot.getRectangle()); if (pdfAnnot.getSubtype().equals("Highlight")) { pdfText = PDFUtil.extractHighlightText(page, pdfAnnot, textColor); } else if (pdfAnnot.getSubtype().equals("Text")) { if (pdfAnnot.getContents() != null) { pdfText = PDFUtil.extractNoteText(pdfAnnot, textColor); } } return pdfText; }
/** * Checks if flags of the annotation are authorized. * * <UL> * <li>Print flag must be 1 * <li>NoView flag must be 0 * <li>Hidden flag must be 0 * <li>Invisible flag must be 0 * </UL> * * If one of these flags is invalid, the errors list is updated with the * ERROR_ANNOT_FORBIDDEN_FLAG ValidationError code. * * @param errors list of errors which is updated if validation fails * @return false if a flag is invalid, true otherwise. */ protected boolean checkFlags(List<ValidationError> errors) { boolean result = this.pdAnnot.isPrinted(); result = result && !this.pdAnnot.isHidden(); result = result && !this.pdAnnot.isInvisible(); result = result && !this.pdAnnot.isNoView(); if (!result) { errors.add( new ValidationResult.ValidationError( ValidationConstants.ERROR_ANNOT_FORBIDDEN_FLAG, "Flags of " + pdAnnot.getSubtype() + " annotation are invalid")); } return result; }