Example usage for org.apache.pdfbox.pdmodel.common PDRectangle getLowerLeftY

List of usage examples for org.apache.pdfbox.pdmodel.common PDRectangle getLowerLeftY

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.common PDRectangle getLowerLeftY.

Prototype

public float getLowerLeftY() 

Source Link

Document

This will get the lower left y coordinate.

Usage

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

License:Apache License

@Override
public int compare(final PdfTextField o1, final PdfTextField o2) {

    PDRectangle r1 = o1.getRectangle();
    PDRectangle r2 = o2.getRectangle();/*w ww. j  a va 2  s . c  om*/

    int v1 = Math.round(r1.getLowerLeftY());
    int v2 = Math.round(r2.getLowerLeftY());
    int r = Integer.compare(v1, v2);

    if (r == 0) {
        v1 = Math.round(r1.getLowerLeftX());
        v2 = Math.round(r2.getLowerLeftX());
        r = Integer.compare(v2, v1);
    }

    return r;
}

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

License:Apache License

/**
 * Calculate the Distance between two {@link PDRectangle}.
 * @param r1 {@link PDRectangle}/*from  ww w  . j a v a 2s  .c  o m*/
 * @param r2 {@link PDRectangle}
 * @return float
 */
public static float getDistanceBetween(final PDRectangle r1, final PDRectangle r2) {
    float dx = min(
            min(abs(r1.getLowerLeftX() - r2.getLowerLeftX()), abs(r1.getUpperRightX() - r2.getUpperRightX())),
            min(abs(r1.getLowerLeftX() - r2.getUpperRightX()), abs(r1.getUpperRightX() - r2.getLowerLeftX())));

    float dy = min(
            min(abs(r1.getLowerLeftY() - r2.getLowerLeftY()), abs(r1.getUpperRightY() - r2.getUpperRightY())),
            min(abs(r1.getLowerLeftY() - r2.getUpperRightY()), abs(r1.getUpperRightY() - r2.getLowerLeftY())));

    return dx + dy;
}

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

License:Apache License

/**
 * Do 2 {@link PDRectangle} intersect.//from www .j  ava2s.  co m
 * @param r1 {@link PDRectangle}
 * @param r2 {@link PDRectangle}
 * @return boolean
 */
public static boolean isIntersection(final PDRectangle r1, final PDRectangle r2) {
    return r1 != null && r2 != null && r1.getLowerLeftX() < r2.getLowerLeftX() + r2.getWidth()
            && r1.getLowerLeftX() + r1.getWidth() > r2.getLowerLeftX()
            && r1.getLowerLeftY() < r2.getLowerLeftY() + r2.getHeight()
            && r1.getLowerLeftY() + r1.getHeight() > r2.getLowerLeftY();
}

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

License:Apache License

@Override
public int compare(final PDRectangle r1, final PDRectangle r2) {
    return Float.compare(r1.getLowerLeftY(), r2.getLowerLeftY());
}

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}//from w w w .j av  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}/*from w  w  w  .j av  a 2  s.co  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  ww w . j  av a 2s  . co 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;
}

From source file:com.infoimage.infotrac.pdfbox.PDFTextAnnotator.java

License:Apache License

private float[] computeQuads(PDRectangle rect) {
    float[] quads = new float[8];
    // top left/*from w  ww.  java2s .c  o m*/
    quads[0] = rect.getLowerLeftX(); // x1
    quads[1] = rect.getUpperRightY() - 2; // y1
    // bottom left
    quads[2] = rect.getUpperRightX(); // x2
    quads[3] = quads[1]; // y2
    // top right
    quads[4] = quads[0]; // x3
    quads[5] = rect.getLowerLeftY() - 2; // y3
    // bottom right
    quads[6] = quads[2]; // x4
    quads[7] = quads[5]; // y4
    return quads;
}

From source file:com.jaromin.alfresco.repo.content.transform.CorelDrawContentTransformer.java

License:Apache License

/**
 * /*  ww  w.  jav  a 2  s.c om*/
 * @param pageImages
 * @param out
 * @throws IOException
 * @throws FileNotFoundException
 * @throws COSVisitorException
 */
private void buildPdfFromImages(Map<File, Dimension> pageImages, OutputStream out)
        throws IOException, FileNotFoundException, COSVisitorException {
    PDDocument doc = new PDDocument();
    for (Map.Entry<File, Dimension> entry : pageImages.entrySet()) {
        File pFile = entry.getKey();
        Dimension d = entry.getValue();
        PDRectangle size = new PDRectangle(d.width, d.height);
        PDPage page = new PDPage(size);
        doc.addPage(page);

        PDXObjectImage ximage = new PDJpeg(doc, new FileInputStream(pFile));
        PDPageContentStream contentStream = new PDPageContentStream(doc, page);
        contentStream.drawImage(ximage, size.getLowerLeftX(), size.getLowerLeftY());
        contentStream.close();
    }
    doc.save(out);
}

From source file:com.repeatability.pdf.PDFTextStripper.java

License:Apache License

private void fillBeadRectangles(PDPage page) {
    beadRectangles = new ArrayList<PDRectangle>();
    for (PDThreadBead bead : page.getThreadBeads()) {
        if (bead == null) {
            // can't skip, because of null entry handling in processTextPosition()
            beadRectangles.add(null);//  w w w  .  j ava 2  s.co m
            continue;
        }

        PDRectangle rect = bead.getRectangle();

        // bead rectangle is in PDF coordinates (y=0 is bottom),
        // glyphs are in image coordinates (y=0 is top),
        // so we must flip
        PDRectangle mediaBox = page.getMediaBox();
        float upperRightY = mediaBox.getUpperRightY() - rect.getLowerLeftY();
        float lowerLeftY = mediaBox.getUpperRightY() - rect.getUpperRightY();
        rect.setLowerLeftY(lowerLeftY);
        rect.setUpperRightY(upperRightY);

        // adjust for cropbox
        PDRectangle cropBox = page.getCropBox();
        if (cropBox.getLowerLeftX() != 0 || cropBox.getLowerLeftY() != 0) {
            rect.setLowerLeftX(rect.getLowerLeftX() - cropBox.getLowerLeftX());
            rect.setLowerLeftY(rect.getLowerLeftY() - cropBox.getLowerLeftY());
            rect.setUpperRightX(rect.getUpperRightX() - cropBox.getLowerLeftX());
            rect.setUpperRightY(rect.getUpperRightY() - cropBox.getLowerLeftY());
        }

        beadRectangles.add(rect);
    }
}