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

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

Introduction

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

Prototype

public void setUpperRightY(float value) 

Source Link

Document

This will set the upper right y coordinate.

Usage

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

License:Apache License

/**
 * Calculate {@link PDRectangle} from a {@link Stream} of
 * {@link PDRectangle}./*w  w w .j  av  a 2  s.co  m*/
 *
 * @param list {@link List} of {@link PDRectangle}
 * @return {@link PDRectangle}
 */
public static PDRectangle calculate(final List<PDRectangle> list) {

    PDRectangle r = new PDRectangle();

    r.setLowerLeftX(round(minimum(list.stream().map(s -> Float.valueOf(s.getLowerLeftX())))));

    r.setUpperRightX(round(maximum(list.stream().map(s -> Float.valueOf(s.getUpperRightX())))));

    r.setLowerLeftY(round(minimum(list.stream().map(s -> Float.valueOf(s.getLowerLeftY())))));

    r.setUpperRightY(round(maximum(list.stream().map(s -> Float.valueOf(s.getUpperRightY())))));

    return r;
}

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

License:Apache License

/**
 * Calculate the {@link PDRectangle} of {@link TextPosition}.
 * @param widgets {@link List}//from  w  w w. ja  v  a 2s . co m
 * @return {@link PDRectangle}
 */
public static PDRectangle calculateWidget(final List<PDAnnotationWidget> widgets) {
    // TODO change to  PDRectangle calculate(final List<PDRectangle> list) {
    PDRectangle r = new PDRectangle();

    r.setLowerLeftX(round(minimum(widgets.stream().map(s -> Float.valueOf(s.getRectangle().getLowerLeftX())))));

    r.setUpperRightX(
            round(maximum(widgets.stream().map(s -> Float.valueOf(s.getRectangle().getUpperRightX())))));

    r.setLowerLeftY(round(minimum(widgets.stream().map(s -> Float.valueOf(s.getRectangle().getLowerLeftY())))));

    r.setUpperRightY(
            round(maximum(widgets.stream().map(s -> Float.valueOf(s.getRectangle().getUpperRightY())))));

    return r;
}

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

License:Apache License

private PDRectangle boundingBox(float lowerLeftX, float lowerLeftY, float upperRightX, float upperRightY) {
    PDRectangle boundingBox = new PDRectangle();
    boundingBox.setLowerLeftX(lowerLeftX);
    boundingBox.setLowerLeftY(lowerLeftY);
    boundingBox.setUpperRightX(upperRightX);
    boundingBox.setUpperRightY(upperRightY);
    return boundingBox;
}

From source file:com.ing.connector.report.WReport.java

License:Open Source License

private void drawUnderline(List annotations) {
    //Registrar.logInfoMessage("Inside drawUnderline");
    Set keys = yPositionAndWidth.keySet();
    //Registrar.logInfoMessage("yPositionAndWidth.keySet().size()" + yPositionAndWidth.keySet().size());

    for (Iterator iterator = keys.iterator(); iterator.hasNext();) {
        //Registrar.logInfoMessage("Inside drawUnderline iterator");
        float yPosition = (Float) iterator.next();
        float textWidth = (Float) yPositionAndWidth.get(yPosition);

        PDAnnotationLine underline = new PDAnnotationLine();
        PDRectangle position = new PDRectangle();
        position.setLowerLeftX(LEFT_EDGE);
        position.setLowerLeftY(yPosition - 3);
        //Registrar.logInfoMessage("LEFT_EDGE: " + LEFT_EDGE);
        //Registrar.logInfoMessage("yPosition: " + yPosition);
        position.setUpperRightX(LEFT_EDGE + 10);
        position.setUpperRightY(yPosition - 3);
        underline.setRectangle(position);

        float[] linepos = new float[4];
        linepos[0] = LEFT_EDGE;/* ww  w  . j  ava2  s.c om*/
        linepos[1] = yPosition - 3;
        linepos[2] = LEFT_EDGE + textWidth;
        linepos[3] = yPosition - 3;
        underline.setLine(linepos);

        underline.setColour(colourBlack);

        // add to the annotations on the page
        annotations.add(underline);
    }

}

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);/*from  w w w.  j a  va 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);
    }
}

From source file:de.berber.kindle.annotator.lib.Comment.java

License:Apache License

@Override
protected PDAnnotation toPDAnnotation(final @Nonnull PDDocumentOutline documentOutline,
        final @Nonnull PDPage page) {
    LOG.info("Creating annotation " + xPositionFactor + "/" + yPositionFactor + " -> " + text);

    // Create annotation text with background color
    final PDGamma pdColor = getColor();
    final PDAnnotationText textAnnotation = new PDAnnotationText();
    textAnnotation.setContents(getText());
    textAnnotation.setColour(pdColor);/*from w ww  .  j  a  va 2s .c  o  m*/

    // set the text position
    final PDRectangle cropBox = page.getTrimBox();
    final PDRectangle position = new PDRectangle();
    position.setLowerLeftX((float) (cropBox.getLowerLeftX()
            + xPositionFactor * (cropBox.getUpperRightX() - cropBox.getLowerLeftX())));
    position.setUpperRightX((float) (cropBox.getLowerLeftX()
            + xPositionFactor * (cropBox.getUpperRightX() - cropBox.getLowerLeftX())));

    position.setUpperRightY((float) (cropBox.getUpperRightY()
            - yPositionFactor * (cropBox.getUpperRightY() - cropBox.getLowerLeftY())));
    position.setLowerLeftY((float) (cropBox.getUpperRightY()
            - yPositionFactor * (cropBox.getUpperRightY() - cropBox.getLowerLeftY())));

    textAnnotation.setRectangle(position);

    return textAnnotation;
}

From source file:de.berber.kindle.annotator.lib.Marking.java

License:Apache License

@Override
protected PDAnnotation toPDAnnotation(final PDDocumentOutline documentOutline, final PDPage page) {
    LOG.info("Creating marking " + leftXPositionFactor + "/" + lowerYPositionFactor + " -> "
            + rightXPositionFactor + "/" + upperYPositionFactor);

    // create highlighted area
    final PDGamma pdColor = getColor();
    // final PDFont font = PDType1Font.HELVETICA_BOLD;
    // float textHeight = font.getFontHeight("Hg".getBytes(), 0, 2);

    final PDAnnotationTextMarkup txtMark = new PDAnnotationTextMarkup(
            PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
    txtMark.setColour(pdColor);/*from w w w .  jav a  2  s . co  m*/
    txtMark.setConstantOpacity(opacity);

    if (comment != null) {
        // set comment if available
        txtMark.setContents(comment.getText());
    }

    // Set the rectangle containing the markup
    final PDRectangle cropBox = page.getTrimBox();

    final PDRectangle position = new PDRectangle();
    position.setLowerLeftX((float) (cropBox.getLowerLeftX()
            + leftXPositionFactor * (cropBox.getUpperRightX() - cropBox.getLowerLeftX())));
    position.setUpperRightX((float) (cropBox.getLowerLeftX()
            + rightXPositionFactor * (cropBox.getUpperRightX() - cropBox.getLowerLeftX())));

    position.setLowerLeftY((float) (cropBox.getUpperRightY()
            - (lowerYPositionFactor + ((upperYPositionFactor - lowerYPositionFactor == 0.0) ? 0.025 : 0.00))
                    * (cropBox.getUpperRightY() - cropBox.getLowerLeftY())));
    position.setUpperRightY((float) (cropBox.getUpperRightY()
            - (upperYPositionFactor) * (cropBox.getUpperRightY() - cropBox.getLowerLeftY())));

    txtMark.setRectangle(position);
    // work out the points forming the four corners of the annotations
    // set out in anti clockwise form (Completely wraps the text)
    // OK, the below doesn't match that description.
    // It's what acrobat 7 does and displays properly!

    float[] quads = new float[8];

    quads[0] = position.getLowerLeftX(); // x1
    quads[1] = position.getUpperRightY(); // y1
    quads[2] = position.getUpperRightX(); // x2
    quads[3] = position.getUpperRightY(); // y2
    quads[4] = position.getLowerLeftX(); // x3
    quads[5] = position.getLowerLeftY(); // y3
    quads[6] = position.getUpperRightX(); // x4
    quads[7] = position.getLowerLeftY(); // y5

    txtMark.setQuadPoints(quads);

    return txtMark;
}

From source file:helper.pdfpreprocessing.pdf.TextHighlight.java

License:Apache License

private boolean markupMatch(Color color, PDPageContentStream contentStream, Match markingMatch, int height,
        boolean withId, PDPage page, String comment, boolean commentOnly) throws IOException {
    final List<PDRectangle> textBoundingBoxes = getTextBoundingBoxes(markingMatch.positions);

    if (textBoundingBoxes.size() > 0) {
        contentStream.setNonStrokingColor(color);
        for (PDRectangle textBoundingBox : textBoundingBoxes) {
            if (comment.isEmpty()) {
                contentStream.addRect(textBoundingBox.getLowerLeftX(), textBoundingBox.getLowerLeftY(), Math
                        .max(Math.abs(textBoundingBox.getUpperRightX() - textBoundingBox.getLowerLeftX()), 10),
                        height);/*from   w  ww . java  2s  .  co m*/
                contentStream.fill();
            }
            if (withId) {
                PDFont font = PDType1Font.HELVETICA;
                contentStream.beginText();
                contentStream.setFont(font, 5);
                contentStream.newLineAtOffset(textBoundingBox.getUpperRightX(),
                        textBoundingBox.getUpperRightY());
                contentStream.showText(markingMatch.str);
                contentStream.endText();
            }
            if (!comment.isEmpty() && !commentOnly) {
                PDAnnotationTextMarkup txtMark = new PDAnnotationTextMarkup(
                        PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
                PDRectangle position = new PDRectangle();
                position.setLowerLeftX(textBoundingBox.getLowerLeftX());
                position.setLowerLeftY(textBoundingBox.getLowerLeftY());
                position.setUpperRightX(textBoundingBox.getLowerLeftX() + Math
                        .max(Math.abs(textBoundingBox.getUpperRightX() - textBoundingBox.getLowerLeftX()), 10));
                position.setUpperRightY(textBoundingBox.getLowerLeftY() + 10);
                txtMark.setRectangle(position);

                float[] quads = new float[8];
                quads[0] = position.getLowerLeftX(); // x1
                quads[1] = position.getUpperRightY() - 2; // y1
                quads[2] = position.getUpperRightX(); // x2
                quads[3] = quads[1]; // y2
                quads[4] = quads[0]; // x3
                quads[5] = position.getLowerLeftY() - 2; // y3
                quads[6] = quads[2]; // x4
                quads[7] = quads[5]; // y5
                txtMark.setQuadPoints(quads);
                txtMark.setConstantOpacity((float) 0.5);
                txtMark.setContents("Missing Assumption/s (" + markingMatch.str + "):\n" + comment);
                float[] colorArray = new float[] { 0, 0, 0 };
                colorArray = color.getColorComponents(colorArray);
                PDColor hColor = new PDColor(colorArray, PDDeviceRGB.INSTANCE);
                txtMark.setColor(hColor);
                txtMark.setCreationDate(Calendar.getInstance());
                txtMark.setTitlePopup("Assumption Error");
                page.getAnnotations().add(txtMark);
            } else if (!comment.isEmpty() && commentOnly) {
                for (int i = 0; i < page.getAnnotations().size(); i++) {
                    String extractedComment = page.getAnnotations().get(i).getContents();
                    if (extractedComment != null) {
                        String commentID = extractedComment.substring(extractedComment.indexOf("(") + 1,
                                extractedComment.indexOf(")"));
                        if (markingMatch.str.equals(commentID) && extractedComment.contains(comment)) {
                            page.getAnnotations().get(i).setContents(extractedComment + "\n" + comment);
                        }

                    }
                }
            }
        }
        return true;
    }
    return false;
}

From source file:model.util.pdf.PDFUtils.java

License:Apache License

private static void changeCropBox(PDDocument document, float a, float b, float c, float d) {
    for (PDPage page : document.getPages()) {
        PDRectangle rectangle = new PDRectangle();
        rectangle.setLowerLeftX(a);/*from  w  w  w . j a v  a  2s. co m*/
        rectangle.setLowerLeftY(b);
        rectangle.setUpperRightX(c);
        rectangle.setUpperRightY(d);
        page.setCropBox(rectangle);

    }
}

From source file:org.apache.fop.render.pdf.pdfbox.PDFBoxAdapter.java

License:Apache License

private void moveAnnotations(PDPage page, List pageAnnotations, AffineTransform at) {
    PDRectangle mediaBox = page.getMediaBox();
    PDRectangle cropBox = page.getCropBox();
    PDRectangle viewBox = cropBox != null ? cropBox : mediaBox;
    for (Object obj : pageAnnotations) {
        PDAnnotation annot = (PDAnnotation) obj;
        PDRectangle rect = annot.getRectangle();
        float translateX = (float) (at.getTranslateX() - viewBox.getLowerLeftX());
        float translateY = (float) (at.getTranslateY() - viewBox.getLowerLeftY());
        if (rect != null) {
            rect.setUpperRightX(rect.getUpperRightX() + translateX);
            rect.setLowerLeftX(rect.getLowerLeftX() + translateX);
            rect.setUpperRightY(rect.getUpperRightY() + translateY);
            rect.setLowerLeftY(rect.getLowerLeftY() + translateY);
            annot.setRectangle(rect);//from   w  ww .j  av a 2  s .  co  m
        }
        //            COSArray vertices = (COSArray) annot.getCOSObject().getDictionaryObject("Vertices");
        //            if (vertices != null) {
        //                Iterator iter = vertices.iterator();
        //                while (iter.hasNext()) {
        //                    COSFloat x = (COSFloat) iter.next();
        //                    COSFloat y = (COSFloat) iter.next();
        //                    x.setValue(x.floatValue() + translateX);
        //                    y.setValue(y.floatValue() + translateY);
        //                }
        //            }
    }
}