Example usage for org.apache.pdfbox.pdmodel.interactive.annotation PDAnnotationWidget getRectangle

List of usage examples for org.apache.pdfbox.pdmodel.interactive.annotation PDAnnotationWidget getRectangle

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.interactive.annotation PDAnnotationWidget getRectangle.

Prototype

public PDRectangle getRectangle() 

Source Link

Document

The annotation rectangle, defining the location of the annotation on the page in default user space units.

Usage

From source file:com.formkiq.core.service.generator.pdfbox.PdfEditorServiceImpl.java

License:Apache License

/**
 * Find Text for {@link PDAnnotationWidget}.
 * @param widget {@link PDAnnotationWidget}
 * @param fields {@link List}//from   w ww. j  ava2  s  .  c o  m
 * @param searchAreas {@link List} of {@link PDFieldSearchRectangle}
 * @return {@link PdAnnotationWidgetMatch}
 */
private List<PdfTextFieldMatch> findTextForWidget(final PDAnnotationWidget widget,
        final List<PdfTextField> fields, final List<PDFieldSearchRectangle> searchAreas) {

    PDRectangle rect = widget.getRectangle();

    List<PdfTextFieldMatch> matches = findPossibleMatches(rect, fields, searchAreas);

    return matches;
}

From source file:com.formkiq.core.service.generator.pdfbox.TextSearchAreaFilterDefault.java

License:Apache License

/**
 * Calculate Horziontal Matching Rectangle by field type.
 *
 * @param page {@link PDPage}/*  w  ww.ja  v  a  2 s  .  c o m*/
 * @param field {@link PDField}
 * @param w {@link PDAnnotationWidget}
 * @return {@link PDRectangle}
 */
private PDRectangle getHorizontalRectangle(final PDPage page, final PDField field, final PDAnnotationWidget w) {

    PDRectangle wrect = w.getRectangle();
    PDRectangle rect = new PDRectangle(0, wrect.getLowerLeftY(), wrect.getWidth() + wrect.getLowerLeftX(),
            wrect.getHeight());

    if (field instanceof PDCheckBox) {
        rect = new PDRectangle(0, wrect.getLowerLeftY(), page.getMediaBox().getWidth(), wrect.getHeight());
    }

    return rect;
}

From source file:com.formkiq.core.service.generator.pdfbox.TextSearchAreaFilterDefault.java

License:Apache License

/**
 * Calculate Vertical Matching Rectangle by field type.
 *
 * @param field {@link PDField}/* www  . jav  a  2 s.  c o  m*/
 * @param w {@link PDAnnotationWidget}
 * @return {@link PDRectangle}
 */
private PDRectangle getVerticalRectangle(final PDField field, final PDAnnotationWidget w) {

    PDRectangle rect = null;

    if (!(field instanceof PDCheckBox)) {

        PDRectangle wrect = w.getRectangle();
        float addition = 2 * wrect.getHeight();

        rect = new PDRectangle(wrect.getLowerLeftX() - addition, wrect.getLowerLeftY(),
                wrect.getWidth() + addition, wrect.getHeight() + addition);
    }

    return rect;
}

From source file:com.formkiq.core.service.generator.pdfbox.TextSearchAreaFilterInsideLines.java

License:Apache License

@Override
public List<PDFieldSearchRectangle> getTextSearchArea(final PDPage page, final PDField pdField,
        final PDAnnotationWidget widget, final List<PDRectangle> lineRects) {

    List<PDFieldSearchRectangle> area = new ArrayList<>(1);
    PDRectangle wrect = widget.getRectangle();

    List<PDRectangle> leftlist = new ArrayList<>();
    List<PDRectangle> rightlist = new ArrayList<>();
    List<PDRectangle> toplist = new ArrayList<>();
    List<PDRectangle> bottomlist = new ArrayList<>();

    for (PDRectangle line : lineRects) {

        if (line.getLowerLeftY() < wrect.getLowerLeftY() && wrect.getUpperRightY() < line.getUpperRightY()) {

            if (line.getUpperRightX() < wrect.getLowerLeftX()) {
                leftlist.add(line);/*from  w  ww. jav a 2s . c  o  m*/
            } else if (wrect.getUpperRightX() < line.getLowerLeftX()) {
                rightlist.add(line);
            }
        }

        if (line.getLowerLeftX() < wrect.getLowerLeftX() && wrect.getUpperRightX() < line.getUpperRightX()) {

            if (line.getUpperRightY() < wrect.getLowerLeftY()) {
                bottomlist.add(line);
            } else if (wrect.getUpperRightY() < line.getUpperRightY()) {
                toplist.add(line);
            }
        }
    }

    PDRectangle left = !leftlist.isEmpty() ? Collections.max(leftlist, new PDRectangleXComparator()) : null;
    PDRectangle right = !rightlist.isEmpty() ? Collections.min(rightlist, new PDRectangleXComparator()) : null;
    PDRectangle top = !toplist.isEmpty() ? Collections.min(toplist, new PDRectangleYComparator()) : null;
    PDRectangle bottom = !bottomlist.isEmpty() ? Collections.max(bottomlist, new PDRectangleYComparator())
            : null;

    if (left != null && right != null && top != null && bottom != null) {
        PDRectangle r = new PDRectangle(left.getLowerLeftX(), bottom.getLowerLeftY(),
                right.getUpperRightX() - left.getLowerLeftX(), top.getUpperRightY() - bottom.getLowerLeftY());

        area.add(new PDFieldSearchRectangle(PDFieldAreaSearch.RECTANGLE, r));
    }

    return area;
}