List of usage examples for org.apache.pdfbox.pdmodel PDPage getTrimBox
public PDRectangle getTrimBox()
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 w w .ja v a 2s . co 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);// ww w . ja va 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; }