Example #1
0
  public static PDFText extractNoteText(PDAnnotation pdfAnnot, Color textColor) throws IOException {

    PDRectangle rect = pdfAnnot.getRectangle();
    return new PDFText(
        removeEndOfLineCharacters(pdfAnnot.getContents()),
        PDFText.TextType.NOTE,
        Color.GRAY,
        textColor,
        rect);
  }
Example #2
0
  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;
  }
Example #4
0
  public static PDFText extractHighlightText(PDPage page, PDAnnotation pdfAnnot, Color textColor)
      throws IOException {

    PDFTextStripperByArea stripper = new PDFTextStripperByArea();

    PDRectangle rect = pdfAnnot.getRectangle();
    stripper.setSortByPosition(true);
    stripper.addRegion(Integer.toString(0), getRectangle(page, rect));
    stripper.extractRegions(page);

    String textForRegion =
        removeEndOfLineCharacters(stripper.getTextForRegion(Integer.toString(0)));

    return new PDFText(
        textForRegion, PDFText.TextType.TEXT, PDFUtil.extractColor(pdfAnnot), textColor, rect);
  }
Example #5
0
 public static Color extractColor(PDAnnotation annot) {
   PDGamma colour = annot.getColour();
   return new Color(colour.getR(), colour.getG(), colour.getB());
 }